{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Slicing and Dicing\n",
    "We will be working with the `data/earthquakes.csv` file again, so we need to handle our imports and read it in.\n",
    "\n",
    "## About the Data\n",
    "In this notebook, we will be working with Earthquake data from September 18, 2018 - October 13, 2018 (obtained from the US Geological Survey (USGS) using the [USGS API](https://earthquake.usgs.gov/fdsnws/event/1/))\n",
    "\n",
    "## Setup"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "df = pd.read_csv('data/earthquakes.csv')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Selection of Columns\n",
    "Grab an entire column using attribute notation:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       1.35\n",
       "1       1.29\n",
       "2       3.42\n",
       "3       0.44\n",
       "4       2.16\n",
       "5       2.61\n",
       "6       1.70\n",
       "7       1.13\n",
       "8       0.92\n",
       "9       4.70\n",
       "10      0.50\n",
       "11      2.77\n",
       "12      0.50\n",
       "13      4.50\n",
       "14      2.13\n",
       "15      2.00\n",
       "16      0.72\n",
       "17      1.69\n",
       "18      2.00\n",
       "19      0.92\n",
       "20      2.82\n",
       "21      1.70\n",
       "22      0.81\n",
       "23      0.55\n",
       "24      0.67\n",
       "25      2.10\n",
       "26      2.80\n",
       "27      1.10\n",
       "28      1.80\n",
       "29      0.93\n",
       "        ... \n",
       "9302    1.42\n",
       "9303    1.30\n",
       "9304    5.10\n",
       "9305   -0.27\n",
       "9306    2.86\n",
       "9307    2.44\n",
       "9308    2.10\n",
       "9309    4.80\n",
       "9310    1.10\n",
       "9311    3.27\n",
       "9312    2.50\n",
       "9313    1.50\n",
       "9314    2.00\n",
       "9315    2.74\n",
       "9316    3.08\n",
       "9317    2.64\n",
       "9318    1.10\n",
       "9319    4.40\n",
       "9320    2.81\n",
       "9321    4.30\n",
       "9322    0.40\n",
       "9323    0.60\n",
       "9324    1.06\n",
       "9325    0.51\n",
       "9326    1.82\n",
       "9327    0.62\n",
       "9328    1.00\n",
       "9329    2.40\n",
       "9330    1.10\n",
       "9331    0.66\n",
       "Name: mag, Length: 9332, dtype: float64"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.mag"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Grab an entire column using dictionary syntax:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       1.35\n",
       "1       1.29\n",
       "2       3.42\n",
       "3       0.44\n",
       "4       2.16\n",
       "5       2.61\n",
       "6       1.70\n",
       "7       1.13\n",
       "8       0.92\n",
       "9       4.70\n",
       "10      0.50\n",
       "11      2.77\n",
       "12      0.50\n",
       "13      4.50\n",
       "14      2.13\n",
       "15      2.00\n",
       "16      0.72\n",
       "17      1.69\n",
       "18      2.00\n",
       "19      0.92\n",
       "20      2.82\n",
       "21      1.70\n",
       "22      0.81\n",
       "23      0.55\n",
       "24      0.67\n",
       "25      2.10\n",
       "26      2.80\n",
       "27      1.10\n",
       "28      1.80\n",
       "29      0.93\n",
       "        ... \n",
       "9302    1.42\n",
       "9303    1.30\n",
       "9304    5.10\n",
       "9305   -0.27\n",
       "9306    2.86\n",
       "9307    2.44\n",
       "9308    2.10\n",
       "9309    4.80\n",
       "9310    1.10\n",
       "9311    3.27\n",
       "9312    2.50\n",
       "9313    1.50\n",
       "9314    2.00\n",
       "9315    2.74\n",
       "9316    3.08\n",
       "9317    2.64\n",
       "9318    1.10\n",
       "9319    4.40\n",
       "9320    2.81\n",
       "9321    4.30\n",
       "9322    0.40\n",
       "9323    0.60\n",
       "9324    1.06\n",
       "9325    0.51\n",
       "9326    1.82\n",
       "9327    0.62\n",
       "9328    1.00\n",
       "9329    2.40\n",
       "9330    1.10\n",
       "9331    0.66\n",
       "Name: mag, Length: 9332, dtype: float64"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['mag']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Selecting multiple columns:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>mag</th>\n",
       "      <th>title</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.35</td>\n",
       "      <td>M 1.4 - 9km NE of Aguanga, CA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.29</td>\n",
       "      <td>M 1.3 - 9km NE of Aguanga, CA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3.42</td>\n",
       "      <td>M 3.4 - 8km NE of Aguanga, CA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.44</td>\n",
       "      <td>M 0.4 - 9km NE of Aguanga, CA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2.16</td>\n",
       "      <td>M 2.2 - 10km NW of Avenal, CA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2.61</td>\n",
       "      <td>M 2.6 - 55km ESE of Punta Cana, Dominican Repu...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1.70</td>\n",
       "      <td>M 1.7 - 105km W of Talkeetna, Alaska</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>1.13</td>\n",
       "      <td>M 1.1 - 10km NW of Parkfield, CA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>0.92</td>\n",
       "      <td>M 0.9 - 6km NW of The Geysers, CA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>4.70</td>\n",
       "      <td>M 4.7 - 219km SSE of Saparua, Indonesia</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>0.50</td>\n",
       "      <td>M 0.5 - 10km NE of Aguanga, CA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2.77</td>\n",
       "      <td>M 2.8 - 53km SE of Punta Cana, Dominican Republic</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>0.50</td>\n",
       "      <td>M 0.5 - 9km NE of Aguanga, CA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>4.50</td>\n",
       "      <td>M 4.5 - 120km SSW of Banda Aceh, Indonesia</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>2.13</td>\n",
       "      <td>M 2.1 - 14km NW of Parkfield, CA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>2.00</td>\n",
       "      <td>M 2.0 - 156km WNW of Haines Junction, Canada</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>0.72</td>\n",
       "      <td>M 0.7 - 2km N of The Geysers, CA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>1.69</td>\n",
       "      <td>M 1.7 - 2km S of Maricao, Puerto Rico</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>2.00</td>\n",
       "      <td>M 2.0 - 57km SSW of Kaktovik, Alaska</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>0.92</td>\n",
       "      <td>M 0.9 - 4km ENE of Calimesa, CA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>2.82</td>\n",
       "      <td>M 2.8 - 61km N of Tierras Nuevas Poniente, Pue...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>1.70</td>\n",
       "      <td>M 1.7 - 64km SSW of Salcha, Alaska</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>0.81</td>\n",
       "      <td>M 0.8 - 4km NW of San Clemente, CA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>0.55</td>\n",
       "      <td>M 0.6 - 27km E of Coso Junction, CA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>0.67</td>\n",
       "      <td>M 0.7 - 6km SSE of Idyllwild, CA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>2.10</td>\n",
       "      <td>M 2.1 - 14km NW of Parkfield, CA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>2.80</td>\n",
       "      <td>M 2.8 - 111km NNW of Arctic Village, Alaska</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>1.10</td>\n",
       "      <td>M 1.1 - 43km S of Redoubt Volcano, Alaska</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>1.80</td>\n",
       "      <td>M 1.8 - 86km SW of Anchor Point, Alaska</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>0.93</td>\n",
       "      <td>M 0.9 - 15km NW of Parkfield, CA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9302</th>\n",
       "      <td>1.42</td>\n",
       "      <td>M 1.4 - 6km NW of The Geysers, CA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9303</th>\n",
       "      <td>1.30</td>\n",
       "      <td>M 1.3 - 78km WNW of Arctic Village, Alaska</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9304</th>\n",
       "      <td>5.10</td>\n",
       "      <td>M 5.1 - 34km NW of Finschhafen, Papua New Guinea</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9305</th>\n",
       "      <td>-0.27</td>\n",
       "      <td>M -0.3 - 49km W of Tanaga Volcano, Alaska</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9306</th>\n",
       "      <td>2.86</td>\n",
       "      <td>M 2.9 - 80km NW of San Antonio, Puerto Rico</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9307</th>\n",
       "      <td>2.44</td>\n",
       "      <td>M 2.4 - 69km NW of San Antonio, Puerto Rico</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9308</th>\n",
       "      <td>2.10</td>\n",
       "      <td>M 2.1 - 70km NW of Nikolski, Alaska</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9309</th>\n",
       "      <td>4.80</td>\n",
       "      <td>M 4.8 - 11km ESE of Rotorua, New Zealand</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9310</th>\n",
       "      <td>1.10</td>\n",
       "      <td>M 1.1 - 59km NNE of Sutton-Alpine, Alaska</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9311</th>\n",
       "      <td>3.27</td>\n",
       "      <td>M 3.3 - 68km W of Petrolia, CA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9312</th>\n",
       "      <td>2.50</td>\n",
       "      <td>M 2.5 - 134km NW of Arctic Village, Alaska</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9313</th>\n",
       "      <td>1.50</td>\n",
       "      <td>M 1.5 - 88km ESE of Whittier, Alaska</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9314</th>\n",
       "      <td>2.00</td>\n",
       "      <td>M 2.0 - 132km WNW of Arctic Village, Alaska</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9315</th>\n",
       "      <td>2.74</td>\n",
       "      <td>M 2.7 - 36km NNW of San Antonio, Puerto Rico</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9316</th>\n",
       "      <td>3.08</td>\n",
       "      <td>M 3.1 - 5km SW of Delta, B.C., MX</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9317</th>\n",
       "      <td>2.64</td>\n",
       "      <td>M 2.6 - 4km SW of Delta, B.C., MX</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9318</th>\n",
       "      <td>1.10</td>\n",
       "      <td>M 1.1 - 11km E of Healy, Alaska</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9319</th>\n",
       "      <td>4.40</td>\n",
       "      <td>M 4.4 - 58km W of San Antonio de los Cobres, A...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9320</th>\n",
       "      <td>2.81</td>\n",
       "      <td>M 2.8 - 8km NW of Delta, B.C., MX</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9321</th>\n",
       "      <td>4.30</td>\n",
       "      <td>M 4.3 - 19km NE of Cateel, Philippines</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9322</th>\n",
       "      <td>0.40</td>\n",
       "      <td>M 0.4 - 8km ENE of Mammoth Lakes, CA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9323</th>\n",
       "      <td>0.60</td>\n",
       "      <td>M 0.6 - 4km ENE of Mammoth Lakes, CA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9324</th>\n",
       "      <td>1.06</td>\n",
       "      <td>M 1.1 - 2km W of Julian, CA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9325</th>\n",
       "      <td>0.51</td>\n",
       "      <td>M 0.5 - 4km WNW of Julian, CA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9326</th>\n",
       "      <td>1.82</td>\n",
       "      <td>M 1.8 - 4km W of Julian, CA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9327</th>\n",
       "      <td>0.62</td>\n",
       "      <td>M 0.6 - 9km ENE of Mammoth Lakes, CA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9328</th>\n",
       "      <td>1.00</td>\n",
       "      <td>M 1.0 - 3km W of Julian, CA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9329</th>\n",
       "      <td>2.40</td>\n",
       "      <td>M 2.4 - 35km NNE of Hatillo, Puerto Rico</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9330</th>\n",
       "      <td>1.10</td>\n",
       "      <td>M 1.1 - 9km NE of Aguanga, CA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9331</th>\n",
       "      <td>0.66</td>\n",
       "      <td>M 0.7 - 9km NE of Aguanga, CA</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>9332 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       mag                                              title\n",
       "0     1.35                      M 1.4 - 9km NE of Aguanga, CA\n",
       "1     1.29                      M 1.3 - 9km NE of Aguanga, CA\n",
       "2     3.42                      M 3.4 - 8km NE of Aguanga, CA\n",
       "3     0.44                      M 0.4 - 9km NE of Aguanga, CA\n",
       "4     2.16                      M 2.2 - 10km NW of Avenal, CA\n",
       "5     2.61  M 2.6 - 55km ESE of Punta Cana, Dominican Repu...\n",
       "6     1.70               M 1.7 - 105km W of Talkeetna, Alaska\n",
       "7     1.13                   M 1.1 - 10km NW of Parkfield, CA\n",
       "8     0.92                  M 0.9 - 6km NW of The Geysers, CA\n",
       "9     4.70            M 4.7 - 219km SSE of Saparua, Indonesia\n",
       "10    0.50                     M 0.5 - 10km NE of Aguanga, CA\n",
       "11    2.77  M 2.8 - 53km SE of Punta Cana, Dominican Republic\n",
       "12    0.50                      M 0.5 - 9km NE of Aguanga, CA\n",
       "13    4.50         M 4.5 - 120km SSW of Banda Aceh, Indonesia\n",
       "14    2.13                   M 2.1 - 14km NW of Parkfield, CA\n",
       "15    2.00       M 2.0 - 156km WNW of Haines Junction, Canada\n",
       "16    0.72                   M 0.7 - 2km N of The Geysers, CA\n",
       "17    1.69              M 1.7 - 2km S of Maricao, Puerto Rico\n",
       "18    2.00               M 2.0 - 57km SSW of Kaktovik, Alaska\n",
       "19    0.92                    M 0.9 - 4km ENE of Calimesa, CA\n",
       "20    2.82  M 2.8 - 61km N of Tierras Nuevas Poniente, Pue...\n",
       "21    1.70                 M 1.7 - 64km SSW of Salcha, Alaska\n",
       "22    0.81                 M 0.8 - 4km NW of San Clemente, CA\n",
       "23    0.55                M 0.6 - 27km E of Coso Junction, CA\n",
       "24    0.67                   M 0.7 - 6km SSE of Idyllwild, CA\n",
       "25    2.10                   M 2.1 - 14km NW of Parkfield, CA\n",
       "26    2.80        M 2.8 - 111km NNW of Arctic Village, Alaska\n",
       "27    1.10          M 1.1 - 43km S of Redoubt Volcano, Alaska\n",
       "28    1.80            M 1.8 - 86km SW of Anchor Point, Alaska\n",
       "29    0.93                   M 0.9 - 15km NW of Parkfield, CA\n",
       "...    ...                                                ...\n",
       "9302  1.42                  M 1.4 - 6km NW of The Geysers, CA\n",
       "9303  1.30         M 1.3 - 78km WNW of Arctic Village, Alaska\n",
       "9304  5.10   M 5.1 - 34km NW of Finschhafen, Papua New Guinea\n",
       "9305 -0.27          M -0.3 - 49km W of Tanaga Volcano, Alaska\n",
       "9306  2.86        M 2.9 - 80km NW of San Antonio, Puerto Rico\n",
       "9307  2.44        M 2.4 - 69km NW of San Antonio, Puerto Rico\n",
       "9308  2.10                M 2.1 - 70km NW of Nikolski, Alaska\n",
       "9309  4.80           M 4.8 - 11km ESE of Rotorua, New Zealand\n",
       "9310  1.10          M 1.1 - 59km NNE of Sutton-Alpine, Alaska\n",
       "9311  3.27                     M 3.3 - 68km W of Petrolia, CA\n",
       "9312  2.50         M 2.5 - 134km NW of Arctic Village, Alaska\n",
       "9313  1.50               M 1.5 - 88km ESE of Whittier, Alaska\n",
       "9314  2.00        M 2.0 - 132km WNW of Arctic Village, Alaska\n",
       "9315  2.74       M 2.7 - 36km NNW of San Antonio, Puerto Rico\n",
       "9316  3.08                  M 3.1 - 5km SW of Delta, B.C., MX\n",
       "9317  2.64                  M 2.6 - 4km SW of Delta, B.C., MX\n",
       "9318  1.10                    M 1.1 - 11km E of Healy, Alaska\n",
       "9319  4.40  M 4.4 - 58km W of San Antonio de los Cobres, A...\n",
       "9320  2.81                  M 2.8 - 8km NW of Delta, B.C., MX\n",
       "9321  4.30             M 4.3 - 19km NE of Cateel, Philippines\n",
       "9322  0.40               M 0.4 - 8km ENE of Mammoth Lakes, CA\n",
       "9323  0.60               M 0.6 - 4km ENE of Mammoth Lakes, CA\n",
       "9324  1.06                        M 1.1 - 2km W of Julian, CA\n",
       "9325  0.51                      M 0.5 - 4km WNW of Julian, CA\n",
       "9326  1.82                        M 1.8 - 4km W of Julian, CA\n",
       "9327  0.62               M 0.6 - 9km ENE of Mammoth Lakes, CA\n",
       "9328  1.00                        M 1.0 - 3km W of Julian, CA\n",
       "9329  2.40           M 2.4 - 35km NNE of Hatillo, Puerto Rico\n",
       "9330  1.10                      M 1.1 - 9km NE of Aguanga, CA\n",
       "9331  0.66                      M 0.7 - 9km NE of Aguanga, CA\n",
       "\n",
       "[9332 rows x 2 columns]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[['mag', 'title']]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Selecting columns using list comprehensions and string operations offered by pandas `Series` objects:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>time</th>\n",
       "      <th>mag</th>\n",
       "      <th>magType</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>M 1.4 - 9km NE of Aguanga, CA</td>\n",
       "      <td>1539475168010</td>\n",
       "      <td>1.35</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>M 1.3 - 9km NE of Aguanga, CA</td>\n",
       "      <td>1539475129610</td>\n",
       "      <td>1.29</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>M 3.4 - 8km NE of Aguanga, CA</td>\n",
       "      <td>1539475062610</td>\n",
       "      <td>3.42</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>M 0.4 - 9km NE of Aguanga, CA</td>\n",
       "      <td>1539474978070</td>\n",
       "      <td>0.44</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>M 2.2 - 10km NW of Avenal, CA</td>\n",
       "      <td>1539474716050</td>\n",
       "      <td>2.16</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>M 2.6 - 55km ESE of Punta Cana, Dominican Repu...</td>\n",
       "      <td>1539473686440</td>\n",
       "      <td>2.61</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>M 1.7 - 105km W of Talkeetna, Alaska</td>\n",
       "      <td>1539473176017</td>\n",
       "      <td>1.70</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>M 1.1 - 10km NW of Parkfield, CA</td>\n",
       "      <td>1539473060280</td>\n",
       "      <td>1.13</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>M 0.9 - 6km NW of The Geysers, CA</td>\n",
       "      <td>1539473042310</td>\n",
       "      <td>0.92</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>M 4.7 - 219km SSE of Saparua, Indonesia</td>\n",
       "      <td>1539472814760</td>\n",
       "      <td>4.70</td>\n",
       "      <td>mb</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>M 0.5 - 10km NE of Aguanga, CA</td>\n",
       "      <td>1539471831030</td>\n",
       "      <td>0.50</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>M 2.8 - 53km SE of Punta Cana, Dominican Republic</td>\n",
       "      <td>1539471621260</td>\n",
       "      <td>2.77</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>M 0.5 - 9km NE of Aguanga, CA</td>\n",
       "      <td>1539470934710</td>\n",
       "      <td>0.50</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>M 4.5 - 120km SSW of Banda Aceh, Indonesia</td>\n",
       "      <td>1539470898340</td>\n",
       "      <td>4.50</td>\n",
       "      <td>mb</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>M 2.1 - 14km NW of Parkfield, CA</td>\n",
       "      <td>1539470851950</td>\n",
       "      <td>2.13</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>M 2.0 - 156km WNW of Haines Junction, Canada</td>\n",
       "      <td>1539470304219</td>\n",
       "      <td>2.00</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>M 0.7 - 2km N of The Geysers, CA</td>\n",
       "      <td>1539470237230</td>\n",
       "      <td>0.72</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>M 1.7 - 2km S of Maricao, Puerto Rico</td>\n",
       "      <td>1539468879730</td>\n",
       "      <td>1.69</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>M 2.0 - 57km SSW of Kaktovik, Alaska</td>\n",
       "      <td>1539468687232</td>\n",
       "      <td>2.00</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>M 0.9 - 4km ENE of Calimesa, CA</td>\n",
       "      <td>1539468671340</td>\n",
       "      <td>0.92</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>M 2.8 - 61km N of Tierras Nuevas Poniente, Pue...</td>\n",
       "      <td>1539467908560</td>\n",
       "      <td>2.82</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>M 1.7 - 64km SSW of Salcha, Alaska</td>\n",
       "      <td>1539467905609</td>\n",
       "      <td>1.70</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>M 0.8 - 4km NW of San Clemente, CA</td>\n",
       "      <td>1539467508540</td>\n",
       "      <td>0.81</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>M 0.6 - 27km E of Coso Junction, CA</td>\n",
       "      <td>1539466580200</td>\n",
       "      <td>0.55</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>M 0.7 - 6km SSE of Idyllwild, CA</td>\n",
       "      <td>1539466409430</td>\n",
       "      <td>0.67</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>M 2.1 - 14km NW of Parkfield, CA</td>\n",
       "      <td>1539466356170</td>\n",
       "      <td>2.10</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>M 2.8 - 111km NNW of Arctic Village, Alaska</td>\n",
       "      <td>1539466288954</td>\n",
       "      <td>2.80</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>M 1.1 - 43km S of Redoubt Volcano, Alaska</td>\n",
       "      <td>1539465520462</td>\n",
       "      <td>1.10</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>M 1.8 - 86km SW of Anchor Point, Alaska</td>\n",
       "      <td>1539464607849</td>\n",
       "      <td>1.80</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>M 0.9 - 15km NW of Parkfield, CA</td>\n",
       "      <td>1539464503490</td>\n",
       "      <td>0.93</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9302</th>\n",
       "      <td>M 1.4 - 6km NW of The Geysers, CA</td>\n",
       "      <td>1537236549440</td>\n",
       "      <td>1.42</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9303</th>\n",
       "      <td>M 1.3 - 78km WNW of Arctic Village, Alaska</td>\n",
       "      <td>1537236466605</td>\n",
       "      <td>1.30</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9304</th>\n",
       "      <td>M 5.1 - 34km NW of Finschhafen, Papua New Guinea</td>\n",
       "      <td>1537236235470</td>\n",
       "      <td>5.10</td>\n",
       "      <td>mb</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9305</th>\n",
       "      <td>M -0.3 - 49km W of Tanaga Volcano, Alaska</td>\n",
       "      <td>1537235444640</td>\n",
       "      <td>-0.27</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9306</th>\n",
       "      <td>M 2.9 - 80km NW of San Antonio, Puerto Rico</td>\n",
       "      <td>1537234997910</td>\n",
       "      <td>2.86</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9307</th>\n",
       "      <td>M 2.4 - 69km NW of San Antonio, Puerto Rico</td>\n",
       "      <td>1537234935040</td>\n",
       "      <td>2.44</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9308</th>\n",
       "      <td>M 2.1 - 70km NW of Nikolski, Alaska</td>\n",
       "      <td>1537234649752</td>\n",
       "      <td>2.10</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9309</th>\n",
       "      <td>M 4.8 - 11km ESE of Rotorua, New Zealand</td>\n",
       "      <td>1537234582260</td>\n",
       "      <td>4.80</td>\n",
       "      <td>mb</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9310</th>\n",
       "      <td>M 1.1 - 59km NNE of Sutton-Alpine, Alaska</td>\n",
       "      <td>1537233698073</td>\n",
       "      <td>1.10</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9311</th>\n",
       "      <td>M 3.3 - 68km W of Petrolia, CA</td>\n",
       "      <td>1537233245200</td>\n",
       "      <td>3.27</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9312</th>\n",
       "      <td>M 2.5 - 134km NW of Arctic Village, Alaska</td>\n",
       "      <td>1537233039227</td>\n",
       "      <td>2.50</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9313</th>\n",
       "      <td>M 1.5 - 88km ESE of Whittier, Alaska</td>\n",
       "      <td>1537232989781</td>\n",
       "      <td>1.50</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9314</th>\n",
       "      <td>M 2.0 - 132km WNW of Arctic Village, Alaska</td>\n",
       "      <td>1537232951978</td>\n",
       "      <td>2.00</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9315</th>\n",
       "      <td>M 2.7 - 36km NNW of San Antonio, Puerto Rico</td>\n",
       "      <td>1537232857340</td>\n",
       "      <td>2.74</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9316</th>\n",
       "      <td>M 3.1 - 5km SW of Delta, B.C., MX</td>\n",
       "      <td>1537232823500</td>\n",
       "      <td>3.08</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9317</th>\n",
       "      <td>M 2.6 - 4km SW of Delta, B.C., MX</td>\n",
       "      <td>1537232796810</td>\n",
       "      <td>2.64</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9318</th>\n",
       "      <td>M 1.1 - 11km E of Healy, Alaska</td>\n",
       "      <td>1537232056478</td>\n",
       "      <td>1.10</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9319</th>\n",
       "      <td>M 4.4 - 58km W of San Antonio de los Cobres, A...</td>\n",
       "      <td>1537231966170</td>\n",
       "      <td>4.40</td>\n",
       "      <td>mb</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9320</th>\n",
       "      <td>M 2.8 - 8km NW of Delta, B.C., MX</td>\n",
       "      <td>1537231284810</td>\n",
       "      <td>2.81</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9321</th>\n",
       "      <td>M 4.3 - 19km NE of Cateel, Philippines</td>\n",
       "      <td>1537231275500</td>\n",
       "      <td>4.30</td>\n",
       "      <td>mb</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9322</th>\n",
       "      <td>M 0.4 - 8km ENE of Mammoth Lakes, CA</td>\n",
       "      <td>1537231090700</td>\n",
       "      <td>0.40</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9323</th>\n",
       "      <td>M 0.6 - 4km ENE of Mammoth Lakes, CA</td>\n",
       "      <td>1537230828440</td>\n",
       "      <td>0.60</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9324</th>\n",
       "      <td>M 1.1 - 2km W of Julian, CA</td>\n",
       "      <td>1537230357100</td>\n",
       "      <td>1.06</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9325</th>\n",
       "      <td>M 0.5 - 4km WNW of Julian, CA</td>\n",
       "      <td>1537230344890</td>\n",
       "      <td>0.51</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9326</th>\n",
       "      <td>M 1.8 - 4km W of Julian, CA</td>\n",
       "      <td>1537230230260</td>\n",
       "      <td>1.82</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9327</th>\n",
       "      <td>M 0.6 - 9km ENE of Mammoth Lakes, CA</td>\n",
       "      <td>1537230228060</td>\n",
       "      <td>0.62</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9328</th>\n",
       "      <td>M 1.0 - 3km W of Julian, CA</td>\n",
       "      <td>1537230135130</td>\n",
       "      <td>1.00</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9329</th>\n",
       "      <td>M 2.4 - 35km NNE of Hatillo, Puerto Rico</td>\n",
       "      <td>1537229908180</td>\n",
       "      <td>2.40</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9330</th>\n",
       "      <td>M 1.1 - 9km NE of Aguanga, CA</td>\n",
       "      <td>1537229545350</td>\n",
       "      <td>1.10</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9331</th>\n",
       "      <td>M 0.7 - 9km NE of Aguanga, CA</td>\n",
       "      <td>1537228864470</td>\n",
       "      <td>0.66</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>9332 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                  title           time   mag  \\\n",
       "0                         M 1.4 - 9km NE of Aguanga, CA  1539475168010  1.35   \n",
       "1                         M 1.3 - 9km NE of Aguanga, CA  1539475129610  1.29   \n",
       "2                         M 3.4 - 8km NE of Aguanga, CA  1539475062610  3.42   \n",
       "3                         M 0.4 - 9km NE of Aguanga, CA  1539474978070  0.44   \n",
       "4                         M 2.2 - 10km NW of Avenal, CA  1539474716050  2.16   \n",
       "5     M 2.6 - 55km ESE of Punta Cana, Dominican Repu...  1539473686440  2.61   \n",
       "6                  M 1.7 - 105km W of Talkeetna, Alaska  1539473176017  1.70   \n",
       "7                      M 1.1 - 10km NW of Parkfield, CA  1539473060280  1.13   \n",
       "8                     M 0.9 - 6km NW of The Geysers, CA  1539473042310  0.92   \n",
       "9               M 4.7 - 219km SSE of Saparua, Indonesia  1539472814760  4.70   \n",
       "10                       M 0.5 - 10km NE of Aguanga, CA  1539471831030  0.50   \n",
       "11    M 2.8 - 53km SE of Punta Cana, Dominican Republic  1539471621260  2.77   \n",
       "12                        M 0.5 - 9km NE of Aguanga, CA  1539470934710  0.50   \n",
       "13           M 4.5 - 120km SSW of Banda Aceh, Indonesia  1539470898340  4.50   \n",
       "14                     M 2.1 - 14km NW of Parkfield, CA  1539470851950  2.13   \n",
       "15         M 2.0 - 156km WNW of Haines Junction, Canada  1539470304219  2.00   \n",
       "16                     M 0.7 - 2km N of The Geysers, CA  1539470237230  0.72   \n",
       "17                M 1.7 - 2km S of Maricao, Puerto Rico  1539468879730  1.69   \n",
       "18                 M 2.0 - 57km SSW of Kaktovik, Alaska  1539468687232  2.00   \n",
       "19                      M 0.9 - 4km ENE of Calimesa, CA  1539468671340  0.92   \n",
       "20    M 2.8 - 61km N of Tierras Nuevas Poniente, Pue...  1539467908560  2.82   \n",
       "21                   M 1.7 - 64km SSW of Salcha, Alaska  1539467905609  1.70   \n",
       "22                   M 0.8 - 4km NW of San Clemente, CA  1539467508540  0.81   \n",
       "23                  M 0.6 - 27km E of Coso Junction, CA  1539466580200  0.55   \n",
       "24                     M 0.7 - 6km SSE of Idyllwild, CA  1539466409430  0.67   \n",
       "25                     M 2.1 - 14km NW of Parkfield, CA  1539466356170  2.10   \n",
       "26          M 2.8 - 111km NNW of Arctic Village, Alaska  1539466288954  2.80   \n",
       "27            M 1.1 - 43km S of Redoubt Volcano, Alaska  1539465520462  1.10   \n",
       "28              M 1.8 - 86km SW of Anchor Point, Alaska  1539464607849  1.80   \n",
       "29                     M 0.9 - 15km NW of Parkfield, CA  1539464503490  0.93   \n",
       "...                                                 ...            ...   ...   \n",
       "9302                  M 1.4 - 6km NW of The Geysers, CA  1537236549440  1.42   \n",
       "9303         M 1.3 - 78km WNW of Arctic Village, Alaska  1537236466605  1.30   \n",
       "9304   M 5.1 - 34km NW of Finschhafen, Papua New Guinea  1537236235470  5.10   \n",
       "9305          M -0.3 - 49km W of Tanaga Volcano, Alaska  1537235444640 -0.27   \n",
       "9306        M 2.9 - 80km NW of San Antonio, Puerto Rico  1537234997910  2.86   \n",
       "9307        M 2.4 - 69km NW of San Antonio, Puerto Rico  1537234935040  2.44   \n",
       "9308                M 2.1 - 70km NW of Nikolski, Alaska  1537234649752  2.10   \n",
       "9309           M 4.8 - 11km ESE of Rotorua, New Zealand  1537234582260  4.80   \n",
       "9310          M 1.1 - 59km NNE of Sutton-Alpine, Alaska  1537233698073  1.10   \n",
       "9311                     M 3.3 - 68km W of Petrolia, CA  1537233245200  3.27   \n",
       "9312         M 2.5 - 134km NW of Arctic Village, Alaska  1537233039227  2.50   \n",
       "9313               M 1.5 - 88km ESE of Whittier, Alaska  1537232989781  1.50   \n",
       "9314        M 2.0 - 132km WNW of Arctic Village, Alaska  1537232951978  2.00   \n",
       "9315       M 2.7 - 36km NNW of San Antonio, Puerto Rico  1537232857340  2.74   \n",
       "9316                  M 3.1 - 5km SW of Delta, B.C., MX  1537232823500  3.08   \n",
       "9317                  M 2.6 - 4km SW of Delta, B.C., MX  1537232796810  2.64   \n",
       "9318                    M 1.1 - 11km E of Healy, Alaska  1537232056478  1.10   \n",
       "9319  M 4.4 - 58km W of San Antonio de los Cobres, A...  1537231966170  4.40   \n",
       "9320                  M 2.8 - 8km NW of Delta, B.C., MX  1537231284810  2.81   \n",
       "9321             M 4.3 - 19km NE of Cateel, Philippines  1537231275500  4.30   \n",
       "9322               M 0.4 - 8km ENE of Mammoth Lakes, CA  1537231090700  0.40   \n",
       "9323               M 0.6 - 4km ENE of Mammoth Lakes, CA  1537230828440  0.60   \n",
       "9324                        M 1.1 - 2km W of Julian, CA  1537230357100  1.06   \n",
       "9325                      M 0.5 - 4km WNW of Julian, CA  1537230344890  0.51   \n",
       "9326                        M 1.8 - 4km W of Julian, CA  1537230230260  1.82   \n",
       "9327               M 0.6 - 9km ENE of Mammoth Lakes, CA  1537230228060  0.62   \n",
       "9328                        M 1.0 - 3km W of Julian, CA  1537230135130  1.00   \n",
       "9329           M 2.4 - 35km NNE of Hatillo, Puerto Rico  1537229908180  2.40   \n",
       "9330                      M 1.1 - 9km NE of Aguanga, CA  1537229545350  1.10   \n",
       "9331                      M 0.7 - 9km NE of Aguanga, CA  1537228864470  0.66   \n",
       "\n",
       "     magType  \n",
       "0         ml  \n",
       "1         ml  \n",
       "2         ml  \n",
       "3         ml  \n",
       "4         md  \n",
       "5         md  \n",
       "6         ml  \n",
       "7         md  \n",
       "8         md  \n",
       "9         mb  \n",
       "10        ml  \n",
       "11        md  \n",
       "12        ml  \n",
       "13        mb  \n",
       "14        md  \n",
       "15        ml  \n",
       "16        md  \n",
       "17        md  \n",
       "18        ml  \n",
       "19        ml  \n",
       "20        md  \n",
       "21        ml  \n",
       "22        ml  \n",
       "23        ml  \n",
       "24        ml  \n",
       "25        md  \n",
       "26        ml  \n",
       "27        ml  \n",
       "28        ml  \n",
       "29        md  \n",
       "...      ...  \n",
       "9302      md  \n",
       "9303      ml  \n",
       "9304      mb  \n",
       "9305      ml  \n",
       "9306      md  \n",
       "9307      md  \n",
       "9308      ml  \n",
       "9309      mb  \n",
       "9310      ml  \n",
       "9311      ml  \n",
       "9312      ml  \n",
       "9313      ml  \n",
       "9314      ml  \n",
       "9315      md  \n",
       "9316      ml  \n",
       "9317      ml  \n",
       "9318      ml  \n",
       "9319      mb  \n",
       "9320      ml  \n",
       "9321      mb  \n",
       "9322      md  \n",
       "9323      md  \n",
       "9324      ml  \n",
       "9325      ml  \n",
       "9326      ml  \n",
       "9327      md  \n",
       "9328      ml  \n",
       "9329      md  \n",
       "9330      ml  \n",
       "9331      ml  \n",
       "\n",
       "[9332 rows x 4 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\n",
    "    ['title', 'time']\n",
    "    + [col for col in df.columns if col.startswith('mag')]\n",
    "]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Breaking down this example:\n",
    "1. the list comprehension"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['mag', 'magType']"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[col for col in df.columns if col.startswith('mag')]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2. assembling the list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['title', 'time', 'mag', 'magType']"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "['title', 'time'] \\\n",
    "+ [col for col in df.columns if col.startswith('mag')]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3. using this list as the list of columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>time</th>\n",
       "      <th>mag</th>\n",
       "      <th>magType</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>M 1.4 - 9km NE of Aguanga, CA</td>\n",
       "      <td>1539475168010</td>\n",
       "      <td>1.35</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>M 1.3 - 9km NE of Aguanga, CA</td>\n",
       "      <td>1539475129610</td>\n",
       "      <td>1.29</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>M 3.4 - 8km NE of Aguanga, CA</td>\n",
       "      <td>1539475062610</td>\n",
       "      <td>3.42</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>M 0.4 - 9km NE of Aguanga, CA</td>\n",
       "      <td>1539474978070</td>\n",
       "      <td>0.44</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>M 2.2 - 10km NW of Avenal, CA</td>\n",
       "      <td>1539474716050</td>\n",
       "      <td>2.16</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>M 2.6 - 55km ESE of Punta Cana, Dominican Repu...</td>\n",
       "      <td>1539473686440</td>\n",
       "      <td>2.61</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>M 1.7 - 105km W of Talkeetna, Alaska</td>\n",
       "      <td>1539473176017</td>\n",
       "      <td>1.70</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>M 1.1 - 10km NW of Parkfield, CA</td>\n",
       "      <td>1539473060280</td>\n",
       "      <td>1.13</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>M 0.9 - 6km NW of The Geysers, CA</td>\n",
       "      <td>1539473042310</td>\n",
       "      <td>0.92</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>M 4.7 - 219km SSE of Saparua, Indonesia</td>\n",
       "      <td>1539472814760</td>\n",
       "      <td>4.70</td>\n",
       "      <td>mb</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>M 0.5 - 10km NE of Aguanga, CA</td>\n",
       "      <td>1539471831030</td>\n",
       "      <td>0.50</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>M 2.8 - 53km SE of Punta Cana, Dominican Republic</td>\n",
       "      <td>1539471621260</td>\n",
       "      <td>2.77</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>M 0.5 - 9km NE of Aguanga, CA</td>\n",
       "      <td>1539470934710</td>\n",
       "      <td>0.50</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>M 4.5 - 120km SSW of Banda Aceh, Indonesia</td>\n",
       "      <td>1539470898340</td>\n",
       "      <td>4.50</td>\n",
       "      <td>mb</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>M 2.1 - 14km NW of Parkfield, CA</td>\n",
       "      <td>1539470851950</td>\n",
       "      <td>2.13</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>M 2.0 - 156km WNW of Haines Junction, Canada</td>\n",
       "      <td>1539470304219</td>\n",
       "      <td>2.00</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>M 0.7 - 2km N of The Geysers, CA</td>\n",
       "      <td>1539470237230</td>\n",
       "      <td>0.72</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>M 1.7 - 2km S of Maricao, Puerto Rico</td>\n",
       "      <td>1539468879730</td>\n",
       "      <td>1.69</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>M 2.0 - 57km SSW of Kaktovik, Alaska</td>\n",
       "      <td>1539468687232</td>\n",
       "      <td>2.00</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>M 0.9 - 4km ENE of Calimesa, CA</td>\n",
       "      <td>1539468671340</td>\n",
       "      <td>0.92</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>M 2.8 - 61km N of Tierras Nuevas Poniente, Pue...</td>\n",
       "      <td>1539467908560</td>\n",
       "      <td>2.82</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>M 1.7 - 64km SSW of Salcha, Alaska</td>\n",
       "      <td>1539467905609</td>\n",
       "      <td>1.70</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>M 0.8 - 4km NW of San Clemente, CA</td>\n",
       "      <td>1539467508540</td>\n",
       "      <td>0.81</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>M 0.6 - 27km E of Coso Junction, CA</td>\n",
       "      <td>1539466580200</td>\n",
       "      <td>0.55</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>M 0.7 - 6km SSE of Idyllwild, CA</td>\n",
       "      <td>1539466409430</td>\n",
       "      <td>0.67</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>M 2.1 - 14km NW of Parkfield, CA</td>\n",
       "      <td>1539466356170</td>\n",
       "      <td>2.10</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>M 2.8 - 111km NNW of Arctic Village, Alaska</td>\n",
       "      <td>1539466288954</td>\n",
       "      <td>2.80</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>M 1.1 - 43km S of Redoubt Volcano, Alaska</td>\n",
       "      <td>1539465520462</td>\n",
       "      <td>1.10</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>M 1.8 - 86km SW of Anchor Point, Alaska</td>\n",
       "      <td>1539464607849</td>\n",
       "      <td>1.80</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>M 0.9 - 15km NW of Parkfield, CA</td>\n",
       "      <td>1539464503490</td>\n",
       "      <td>0.93</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9302</th>\n",
       "      <td>M 1.4 - 6km NW of The Geysers, CA</td>\n",
       "      <td>1537236549440</td>\n",
       "      <td>1.42</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9303</th>\n",
       "      <td>M 1.3 - 78km WNW of Arctic Village, Alaska</td>\n",
       "      <td>1537236466605</td>\n",
       "      <td>1.30</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9304</th>\n",
       "      <td>M 5.1 - 34km NW of Finschhafen, Papua New Guinea</td>\n",
       "      <td>1537236235470</td>\n",
       "      <td>5.10</td>\n",
       "      <td>mb</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9305</th>\n",
       "      <td>M -0.3 - 49km W of Tanaga Volcano, Alaska</td>\n",
       "      <td>1537235444640</td>\n",
       "      <td>-0.27</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9306</th>\n",
       "      <td>M 2.9 - 80km NW of San Antonio, Puerto Rico</td>\n",
       "      <td>1537234997910</td>\n",
       "      <td>2.86</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9307</th>\n",
       "      <td>M 2.4 - 69km NW of San Antonio, Puerto Rico</td>\n",
       "      <td>1537234935040</td>\n",
       "      <td>2.44</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9308</th>\n",
       "      <td>M 2.1 - 70km NW of Nikolski, Alaska</td>\n",
       "      <td>1537234649752</td>\n",
       "      <td>2.10</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9309</th>\n",
       "      <td>M 4.8 - 11km ESE of Rotorua, New Zealand</td>\n",
       "      <td>1537234582260</td>\n",
       "      <td>4.80</td>\n",
       "      <td>mb</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9310</th>\n",
       "      <td>M 1.1 - 59km NNE of Sutton-Alpine, Alaska</td>\n",
       "      <td>1537233698073</td>\n",
       "      <td>1.10</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9311</th>\n",
       "      <td>M 3.3 - 68km W of Petrolia, CA</td>\n",
       "      <td>1537233245200</td>\n",
       "      <td>3.27</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9312</th>\n",
       "      <td>M 2.5 - 134km NW of Arctic Village, Alaska</td>\n",
       "      <td>1537233039227</td>\n",
       "      <td>2.50</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9313</th>\n",
       "      <td>M 1.5 - 88km ESE of Whittier, Alaska</td>\n",
       "      <td>1537232989781</td>\n",
       "      <td>1.50</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9314</th>\n",
       "      <td>M 2.0 - 132km WNW of Arctic Village, Alaska</td>\n",
       "      <td>1537232951978</td>\n",
       "      <td>2.00</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9315</th>\n",
       "      <td>M 2.7 - 36km NNW of San Antonio, Puerto Rico</td>\n",
       "      <td>1537232857340</td>\n",
       "      <td>2.74</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9316</th>\n",
       "      <td>M 3.1 - 5km SW of Delta, B.C., MX</td>\n",
       "      <td>1537232823500</td>\n",
       "      <td>3.08</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9317</th>\n",
       "      <td>M 2.6 - 4km SW of Delta, B.C., MX</td>\n",
       "      <td>1537232796810</td>\n",
       "      <td>2.64</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9318</th>\n",
       "      <td>M 1.1 - 11km E of Healy, Alaska</td>\n",
       "      <td>1537232056478</td>\n",
       "      <td>1.10</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9319</th>\n",
       "      <td>M 4.4 - 58km W of San Antonio de los Cobres, A...</td>\n",
       "      <td>1537231966170</td>\n",
       "      <td>4.40</td>\n",
       "      <td>mb</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9320</th>\n",
       "      <td>M 2.8 - 8km NW of Delta, B.C., MX</td>\n",
       "      <td>1537231284810</td>\n",
       "      <td>2.81</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9321</th>\n",
       "      <td>M 4.3 - 19km NE of Cateel, Philippines</td>\n",
       "      <td>1537231275500</td>\n",
       "      <td>4.30</td>\n",
       "      <td>mb</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9322</th>\n",
       "      <td>M 0.4 - 8km ENE of Mammoth Lakes, CA</td>\n",
       "      <td>1537231090700</td>\n",
       "      <td>0.40</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9323</th>\n",
       "      <td>M 0.6 - 4km ENE of Mammoth Lakes, CA</td>\n",
       "      <td>1537230828440</td>\n",
       "      <td>0.60</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9324</th>\n",
       "      <td>M 1.1 - 2km W of Julian, CA</td>\n",
       "      <td>1537230357100</td>\n",
       "      <td>1.06</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9325</th>\n",
       "      <td>M 0.5 - 4km WNW of Julian, CA</td>\n",
       "      <td>1537230344890</td>\n",
       "      <td>0.51</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9326</th>\n",
       "      <td>M 1.8 - 4km W of Julian, CA</td>\n",
       "      <td>1537230230260</td>\n",
       "      <td>1.82</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9327</th>\n",
       "      <td>M 0.6 - 9km ENE of Mammoth Lakes, CA</td>\n",
       "      <td>1537230228060</td>\n",
       "      <td>0.62</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9328</th>\n",
       "      <td>M 1.0 - 3km W of Julian, CA</td>\n",
       "      <td>1537230135130</td>\n",
       "      <td>1.00</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9329</th>\n",
       "      <td>M 2.4 - 35km NNE of Hatillo, Puerto Rico</td>\n",
       "      <td>1537229908180</td>\n",
       "      <td>2.40</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9330</th>\n",
       "      <td>M 1.1 - 9km NE of Aguanga, CA</td>\n",
       "      <td>1537229545350</td>\n",
       "      <td>1.10</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9331</th>\n",
       "      <td>M 0.7 - 9km NE of Aguanga, CA</td>\n",
       "      <td>1537228864470</td>\n",
       "      <td>0.66</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>9332 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                  title           time   mag  \\\n",
       "0                         M 1.4 - 9km NE of Aguanga, CA  1539475168010  1.35   \n",
       "1                         M 1.3 - 9km NE of Aguanga, CA  1539475129610  1.29   \n",
       "2                         M 3.4 - 8km NE of Aguanga, CA  1539475062610  3.42   \n",
       "3                         M 0.4 - 9km NE of Aguanga, CA  1539474978070  0.44   \n",
       "4                         M 2.2 - 10km NW of Avenal, CA  1539474716050  2.16   \n",
       "5     M 2.6 - 55km ESE of Punta Cana, Dominican Repu...  1539473686440  2.61   \n",
       "6                  M 1.7 - 105km W of Talkeetna, Alaska  1539473176017  1.70   \n",
       "7                      M 1.1 - 10km NW of Parkfield, CA  1539473060280  1.13   \n",
       "8                     M 0.9 - 6km NW of The Geysers, CA  1539473042310  0.92   \n",
       "9               M 4.7 - 219km SSE of Saparua, Indonesia  1539472814760  4.70   \n",
       "10                       M 0.5 - 10km NE of Aguanga, CA  1539471831030  0.50   \n",
       "11    M 2.8 - 53km SE of Punta Cana, Dominican Republic  1539471621260  2.77   \n",
       "12                        M 0.5 - 9km NE of Aguanga, CA  1539470934710  0.50   \n",
       "13           M 4.5 - 120km SSW of Banda Aceh, Indonesia  1539470898340  4.50   \n",
       "14                     M 2.1 - 14km NW of Parkfield, CA  1539470851950  2.13   \n",
       "15         M 2.0 - 156km WNW of Haines Junction, Canada  1539470304219  2.00   \n",
       "16                     M 0.7 - 2km N of The Geysers, CA  1539470237230  0.72   \n",
       "17                M 1.7 - 2km S of Maricao, Puerto Rico  1539468879730  1.69   \n",
       "18                 M 2.0 - 57km SSW of Kaktovik, Alaska  1539468687232  2.00   \n",
       "19                      M 0.9 - 4km ENE of Calimesa, CA  1539468671340  0.92   \n",
       "20    M 2.8 - 61km N of Tierras Nuevas Poniente, Pue...  1539467908560  2.82   \n",
       "21                   M 1.7 - 64km SSW of Salcha, Alaska  1539467905609  1.70   \n",
       "22                   M 0.8 - 4km NW of San Clemente, CA  1539467508540  0.81   \n",
       "23                  M 0.6 - 27km E of Coso Junction, CA  1539466580200  0.55   \n",
       "24                     M 0.7 - 6km SSE of Idyllwild, CA  1539466409430  0.67   \n",
       "25                     M 2.1 - 14km NW of Parkfield, CA  1539466356170  2.10   \n",
       "26          M 2.8 - 111km NNW of Arctic Village, Alaska  1539466288954  2.80   \n",
       "27            M 1.1 - 43km S of Redoubt Volcano, Alaska  1539465520462  1.10   \n",
       "28              M 1.8 - 86km SW of Anchor Point, Alaska  1539464607849  1.80   \n",
       "29                     M 0.9 - 15km NW of Parkfield, CA  1539464503490  0.93   \n",
       "...                                                 ...            ...   ...   \n",
       "9302                  M 1.4 - 6km NW of The Geysers, CA  1537236549440  1.42   \n",
       "9303         M 1.3 - 78km WNW of Arctic Village, Alaska  1537236466605  1.30   \n",
       "9304   M 5.1 - 34km NW of Finschhafen, Papua New Guinea  1537236235470  5.10   \n",
       "9305          M -0.3 - 49km W of Tanaga Volcano, Alaska  1537235444640 -0.27   \n",
       "9306        M 2.9 - 80km NW of San Antonio, Puerto Rico  1537234997910  2.86   \n",
       "9307        M 2.4 - 69km NW of San Antonio, Puerto Rico  1537234935040  2.44   \n",
       "9308                M 2.1 - 70km NW of Nikolski, Alaska  1537234649752  2.10   \n",
       "9309           M 4.8 - 11km ESE of Rotorua, New Zealand  1537234582260  4.80   \n",
       "9310          M 1.1 - 59km NNE of Sutton-Alpine, Alaska  1537233698073  1.10   \n",
       "9311                     M 3.3 - 68km W of Petrolia, CA  1537233245200  3.27   \n",
       "9312         M 2.5 - 134km NW of Arctic Village, Alaska  1537233039227  2.50   \n",
       "9313               M 1.5 - 88km ESE of Whittier, Alaska  1537232989781  1.50   \n",
       "9314        M 2.0 - 132km WNW of Arctic Village, Alaska  1537232951978  2.00   \n",
       "9315       M 2.7 - 36km NNW of San Antonio, Puerto Rico  1537232857340  2.74   \n",
       "9316                  M 3.1 - 5km SW of Delta, B.C., MX  1537232823500  3.08   \n",
       "9317                  M 2.6 - 4km SW of Delta, B.C., MX  1537232796810  2.64   \n",
       "9318                    M 1.1 - 11km E of Healy, Alaska  1537232056478  1.10   \n",
       "9319  M 4.4 - 58km W of San Antonio de los Cobres, A...  1537231966170  4.40   \n",
       "9320                  M 2.8 - 8km NW of Delta, B.C., MX  1537231284810  2.81   \n",
       "9321             M 4.3 - 19km NE of Cateel, Philippines  1537231275500  4.30   \n",
       "9322               M 0.4 - 8km ENE of Mammoth Lakes, CA  1537231090700  0.40   \n",
       "9323               M 0.6 - 4km ENE of Mammoth Lakes, CA  1537230828440  0.60   \n",
       "9324                        M 1.1 - 2km W of Julian, CA  1537230357100  1.06   \n",
       "9325                      M 0.5 - 4km WNW of Julian, CA  1537230344890  0.51   \n",
       "9326                        M 1.8 - 4km W of Julian, CA  1537230230260  1.82   \n",
       "9327               M 0.6 - 9km ENE of Mammoth Lakes, CA  1537230228060  0.62   \n",
       "9328                        M 1.0 - 3km W of Julian, CA  1537230135130  1.00   \n",
       "9329           M 2.4 - 35km NNE of Hatillo, Puerto Rico  1537229908180  2.40   \n",
       "9330                      M 1.1 - 9km NE of Aguanga, CA  1537229545350  1.10   \n",
       "9331                      M 0.7 - 9km NE of Aguanga, CA  1537228864470  0.66   \n",
       "\n",
       "     magType  \n",
       "0         ml  \n",
       "1         ml  \n",
       "2         ml  \n",
       "3         ml  \n",
       "4         md  \n",
       "5         md  \n",
       "6         ml  \n",
       "7         md  \n",
       "8         md  \n",
       "9         mb  \n",
       "10        ml  \n",
       "11        md  \n",
       "12        ml  \n",
       "13        mb  \n",
       "14        md  \n",
       "15        ml  \n",
       "16        md  \n",
       "17        md  \n",
       "18        ml  \n",
       "19        ml  \n",
       "20        md  \n",
       "21        ml  \n",
       "22        ml  \n",
       "23        ml  \n",
       "24        ml  \n",
       "25        md  \n",
       "26        ml  \n",
       "27        ml  \n",
       "28        ml  \n",
       "29        md  \n",
       "...      ...  \n",
       "9302      md  \n",
       "9303      ml  \n",
       "9304      mb  \n",
       "9305      ml  \n",
       "9306      md  \n",
       "9307      md  \n",
       "9308      ml  \n",
       "9309      mb  \n",
       "9310      ml  \n",
       "9311      ml  \n",
       "9312      ml  \n",
       "9313      ml  \n",
       "9314      ml  \n",
       "9315      md  \n",
       "9316      ml  \n",
       "9317      ml  \n",
       "9318      ml  \n",
       "9319      mb  \n",
       "9320      ml  \n",
       "9321      mb  \n",
       "9322      md  \n",
       "9323      md  \n",
       "9324      ml  \n",
       "9325      ml  \n",
       "9326      ml  \n",
       "9327      md  \n",
       "9328      ml  \n",
       "9329      md  \n",
       "9330      ml  \n",
       "9331      ml  \n",
       "\n",
       "[9332 rows x 4 columns]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\n",
    "    ['title', 'time']\n",
    "    + [col for col in df.columns if col.startswith('mag')]\n",
    "]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Slicing\n",
    "### Selecting rows\n",
    "Using row numbers (inclusive of first index, exclusive of last):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>alert</th>\n",
       "      <th>cdi</th>\n",
       "      <th>code</th>\n",
       "      <th>detail</th>\n",
       "      <th>dmin</th>\n",
       "      <th>felt</th>\n",
       "      <th>gap</th>\n",
       "      <th>ids</th>\n",
       "      <th>mag</th>\n",
       "      <th>magType</th>\n",
       "      <th>...</th>\n",
       "      <th>sources</th>\n",
       "      <th>status</th>\n",
       "      <th>time</th>\n",
       "      <th>title</th>\n",
       "      <th>tsunami</th>\n",
       "      <th>type</th>\n",
       "      <th>types</th>\n",
       "      <th>tz</th>\n",
       "      <th>updated</th>\n",
       "      <th>url</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>100</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>20280310</td>\n",
       "      <td>https://earthquake.usgs.gov/fdsnws/event/1/que...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>,ak20280310,</td>\n",
       "      <td>1.20</td>\n",
       "      <td>ml</td>\n",
       "      <td>...</td>\n",
       "      <td>,ak,</td>\n",
       "      <td>automatic</td>\n",
       "      <td>1539435449480</td>\n",
       "      <td>M 1.2 - 25km NW of Ester, Alaska</td>\n",
       "      <td>0</td>\n",
       "      <td>earthquake</td>\n",
       "      <td>,geoserve,origin,</td>\n",
       "      <td>-540.0</td>\n",
       "      <td>1539443551010</td>\n",
       "      <td>https://earthquake.usgs.gov/earthquakes/eventp...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>73096756</td>\n",
       "      <td>https://earthquake.usgs.gov/fdsnws/event/1/que...</td>\n",
       "      <td>0.01355</td>\n",
       "      <td>NaN</td>\n",
       "      <td>185.0</td>\n",
       "      <td>,nc73096756,</td>\n",
       "      <td>0.59</td>\n",
       "      <td>md</td>\n",
       "      <td>...</td>\n",
       "      <td>,nc,</td>\n",
       "      <td>automatic</td>\n",
       "      <td>1539435391320</td>\n",
       "      <td>M 0.6 - 8km ESE of Mammoth Lakes, CA</td>\n",
       "      <td>0</td>\n",
       "      <td>earthquake</td>\n",
       "      <td>,geoserve,nearby-cities,origin,phase-data,scit...</td>\n",
       "      <td>-480.0</td>\n",
       "      <td>1539439802162</td>\n",
       "      <td>https://earthquake.usgs.gov/earthquakes/eventp...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>102</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>37388730</td>\n",
       "      <td>https://earthquake.usgs.gov/fdsnws/event/1/que...</td>\n",
       "      <td>0.02987</td>\n",
       "      <td>NaN</td>\n",
       "      <td>39.0</td>\n",
       "      <td>,ci37388730,</td>\n",
       "      <td>1.33</td>\n",
       "      <td>ml</td>\n",
       "      <td>...</td>\n",
       "      <td>,ci,</td>\n",
       "      <td>automatic</td>\n",
       "      <td>1539435293090</td>\n",
       "      <td>M 1.3 - 8km ENE of Aguanga, CA</td>\n",
       "      <td>0</td>\n",
       "      <td>earthquake</td>\n",
       "      <td>,focal-mechanism,geoserve,nearby-cities,origin...</td>\n",
       "      <td>-480.0</td>\n",
       "      <td>1539435940470</td>\n",
       "      <td>https://earthquake.usgs.gov/earthquakes/eventp...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    alert  cdi      code                                             detail  \\\n",
       "100   NaN  NaN  20280310  https://earthquake.usgs.gov/fdsnws/event/1/que...   \n",
       "101   NaN  NaN  73096756  https://earthquake.usgs.gov/fdsnws/event/1/que...   \n",
       "102   NaN  NaN  37388730  https://earthquake.usgs.gov/fdsnws/event/1/que...   \n",
       "\n",
       "        dmin  felt    gap           ids   mag magType  \\\n",
       "100      NaN   NaN    NaN  ,ak20280310,  1.20      ml   \n",
       "101  0.01355   NaN  185.0  ,nc73096756,  0.59      md   \n",
       "102  0.02987   NaN   39.0  ,ci37388730,  1.33      ml   \n",
       "\n",
       "                           ...                          sources     status  \\\n",
       "100                        ...                             ,ak,  automatic   \n",
       "101                        ...                             ,nc,  automatic   \n",
       "102                        ...                             ,ci,  automatic   \n",
       "\n",
       "              time                                 title  tsunami        type  \\\n",
       "100  1539435449480      M 1.2 - 25km NW of Ester, Alaska        0  earthquake   \n",
       "101  1539435391320  M 0.6 - 8km ESE of Mammoth Lakes, CA        0  earthquake   \n",
       "102  1539435293090        M 1.3 - 8km ENE of Aguanga, CA        0  earthquake   \n",
       "\n",
       "                                                 types     tz        updated  \\\n",
       "100                                  ,geoserve,origin, -540.0  1539443551010   \n",
       "101  ,geoserve,nearby-cities,origin,phase-data,scit... -480.0  1539439802162   \n",
       "102  ,focal-mechanism,geoserve,nearby-cities,origin... -480.0  1539435940470   \n",
       "\n",
       "                                                   url  \n",
       "100  https://earthquake.usgs.gov/earthquakes/eventp...  \n",
       "101  https://earthquake.usgs.gov/earthquakes/eventp...  \n",
       "102  https://earthquake.usgs.gov/earthquakes/eventp...  \n",
       "\n",
       "[3 rows x 26 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[100:103]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Selecting rows and columns with chaining"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>100</th>\n",
       "      <td>M 1.2 - 25km NW of Ester, Alaska</td>\n",
       "      <td>1539435449480</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101</th>\n",
       "      <td>M 0.6 - 8km ESE of Mammoth Lakes, CA</td>\n",
       "      <td>1539435391320</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>102</th>\n",
       "      <td>M 1.3 - 8km ENE of Aguanga, CA</td>\n",
       "      <td>1539435293090</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                    title           time\n",
       "100      M 1.2 - 25km NW of Ester, Alaska  1539435449480\n",
       "101  M 0.6 - 8km ESE of Mammoth Lakes, CA  1539435391320\n",
       "102        M 1.3 - 8km ENE of Aguanga, CA  1539435293090"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[['title', 'time']][100:103]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Order doesn't matter here:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[100:103][['title', 'time']].equals(\n",
    "    df[['title', 'time']][100:103]\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Indexing\n",
    "\n",
    "So we know how to select rows and columns, but can we update values? Well, if we try using what we have learned we will see the following warning often:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\users\\molinstefanie\\packt\\venv\\lib\\site-packages\\ipykernel_launcher.py:1: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n"
     ]
    }
   ],
   "source": [
    "df[110:113]['title'] = df[110:113]['title'].str.lower()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note that it worked here, but pandas says we were setting a value on a copy of a slice and that we should use `loc` instead (topic of the following section):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "110               m 1.1 - 35km s of ester, alaska\n",
       "111    m 1.9 - 93km wnw of arctic village, alaska\n",
       "112      m 0.9 - 20km wsw of smith valley, nevada\n",
       "Name: title, dtype: object"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[110:113]['title']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now if we do this with `loc` as the warning suggests, everything goes smoothly. Note we have to lower the end index by one since `loc` is inclusive of endpoints:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "110               m 1.1 - 35km s of ester, alaska\n",
       "111    m 1.9 - 93km wnw of arctic village, alaska\n",
       "112      m 0.9 - 20km wsw of smith valley, nevada\n",
       "Name: title, dtype: object"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[110:112, 'title'] = df.loc[110:112, 'title'].str.lower()\n",
    "df.loc[110:112, 'title']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Location Indexing with `loc`\n",
    "Selection of the format `loc[row_indexer, column_indexer]` where `:` can be used to select all:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0                           M 1.4 - 9km NE of Aguanga, CA\n",
       "1                           M 1.3 - 9km NE of Aguanga, CA\n",
       "2                           M 3.4 - 8km NE of Aguanga, CA\n",
       "3                           M 0.4 - 9km NE of Aguanga, CA\n",
       "4                           M 2.2 - 10km NW of Avenal, CA\n",
       "5       M 2.6 - 55km ESE of Punta Cana, Dominican Repu...\n",
       "6                    M 1.7 - 105km W of Talkeetna, Alaska\n",
       "7                        M 1.1 - 10km NW of Parkfield, CA\n",
       "8                       M 0.9 - 6km NW of The Geysers, CA\n",
       "9                 M 4.7 - 219km SSE of Saparua, Indonesia\n",
       "10                         M 0.5 - 10km NE of Aguanga, CA\n",
       "11      M 2.8 - 53km SE of Punta Cana, Dominican Republic\n",
       "12                          M 0.5 - 9km NE of Aguanga, CA\n",
       "13             M 4.5 - 120km SSW of Banda Aceh, Indonesia\n",
       "14                       M 2.1 - 14km NW of Parkfield, CA\n",
       "15           M 2.0 - 156km WNW of Haines Junction, Canada\n",
       "16                       M 0.7 - 2km N of The Geysers, CA\n",
       "17                  M 1.7 - 2km S of Maricao, Puerto Rico\n",
       "18                   M 2.0 - 57km SSW of Kaktovik, Alaska\n",
       "19                        M 0.9 - 4km ENE of Calimesa, CA\n",
       "20      M 2.8 - 61km N of Tierras Nuevas Poniente, Pue...\n",
       "21                     M 1.7 - 64km SSW of Salcha, Alaska\n",
       "22                     M 0.8 - 4km NW of San Clemente, CA\n",
       "23                    M 0.6 - 27km E of Coso Junction, CA\n",
       "24                       M 0.7 - 6km SSE of Idyllwild, CA\n",
       "25                       M 2.1 - 14km NW of Parkfield, CA\n",
       "26            M 2.8 - 111km NNW of Arctic Village, Alaska\n",
       "27              M 1.1 - 43km S of Redoubt Volcano, Alaska\n",
       "28                M 1.8 - 86km SW of Anchor Point, Alaska\n",
       "29                       M 0.9 - 15km NW of Parkfield, CA\n",
       "                              ...                        \n",
       "9302                    M 1.4 - 6km NW of The Geysers, CA\n",
       "9303           M 1.3 - 78km WNW of Arctic Village, Alaska\n",
       "9304     M 5.1 - 34km NW of Finschhafen, Papua New Guinea\n",
       "9305            M -0.3 - 49km W of Tanaga Volcano, Alaska\n",
       "9306          M 2.9 - 80km NW of San Antonio, Puerto Rico\n",
       "9307          M 2.4 - 69km NW of San Antonio, Puerto Rico\n",
       "9308                  M 2.1 - 70km NW of Nikolski, Alaska\n",
       "9309             M 4.8 - 11km ESE of Rotorua, New Zealand\n",
       "9310            M 1.1 - 59km NNE of Sutton-Alpine, Alaska\n",
       "9311                       M 3.3 - 68km W of Petrolia, CA\n",
       "9312           M 2.5 - 134km NW of Arctic Village, Alaska\n",
       "9313                 M 1.5 - 88km ESE of Whittier, Alaska\n",
       "9314          M 2.0 - 132km WNW of Arctic Village, Alaska\n",
       "9315         M 2.7 - 36km NNW of San Antonio, Puerto Rico\n",
       "9316                    M 3.1 - 5km SW of Delta, B.C., MX\n",
       "9317                    M 2.6 - 4km SW of Delta, B.C., MX\n",
       "9318                      M 1.1 - 11km E of Healy, Alaska\n",
       "9319    M 4.4 - 58km W of San Antonio de los Cobres, A...\n",
       "9320                    M 2.8 - 8km NW of Delta, B.C., MX\n",
       "9321               M 4.3 - 19km NE of Cateel, Philippines\n",
       "9322                 M 0.4 - 8km ENE of Mammoth Lakes, CA\n",
       "9323                 M 0.6 - 4km ENE of Mammoth Lakes, CA\n",
       "9324                          M 1.1 - 2km W of Julian, CA\n",
       "9325                        M 0.5 - 4km WNW of Julian, CA\n",
       "9326                          M 1.8 - 4km W of Julian, CA\n",
       "9327                 M 0.6 - 9km ENE of Mammoth Lakes, CA\n",
       "9328                          M 1.0 - 3km W of Julian, CA\n",
       "9329             M 2.4 - 35km NNE of Hatillo, Puerto Rico\n",
       "9330                        M 1.1 - 9km NE of Aguanga, CA\n",
       "9331                        M 0.7 - 9km NE of Aguanga, CA\n",
       "Name: title, Length: 9332, dtype: object"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[:,'title']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can use `loc` to select specific rows and columns without chaining. If we use row numbers with `loc`, they are now **inclusive** of the end index:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>mag</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>M 0.5 - 10km NE of Aguanga, CA</td>\n",
       "      <td>0.50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>M 2.8 - 53km SE of Punta Cana, Dominican Republic</td>\n",
       "      <td>2.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>M 0.5 - 9km NE of Aguanga, CA</td>\n",
       "      <td>0.50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>M 4.5 - 120km SSW of Banda Aceh, Indonesia</td>\n",
       "      <td>4.50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>M 2.1 - 14km NW of Parkfield, CA</td>\n",
       "      <td>2.13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>M 2.0 - 156km WNW of Haines Junction, Canada</td>\n",
       "      <td>2.00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                title   mag\n",
       "10                     M 0.5 - 10km NE of Aguanga, CA  0.50\n",
       "11  M 2.8 - 53km SE of Punta Cana, Dominican Republic  2.77\n",
       "12                      M 0.5 - 9km NE of Aguanga, CA  0.50\n",
       "13         M 4.5 - 120km SSW of Banda Aceh, Indonesia  4.50\n",
       "14                   M 2.1 - 14km NW of Parkfield, CA  2.13\n",
       "15       M 2.0 - 156km WNW of Haines Junction, Canada  2.00"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[10:15, ['title', 'mag']]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Integer Location Indexing with `iloc`\n",
    "Exclusive of the endpoint just as Python slicing of lists:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>mag</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>M 0.5 - 10km NE of Aguanga, CA</td>\n",
       "      <td>0.50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>M 2.8 - 53km SE of Punta Cana, Dominican Republic</td>\n",
       "      <td>2.77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>M 0.5 - 9km NE of Aguanga, CA</td>\n",
       "      <td>0.50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>M 4.5 - 120km SSW of Banda Aceh, Indonesia</td>\n",
       "      <td>4.50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>M 2.1 - 14km NW of Parkfield, CA</td>\n",
       "      <td>2.13</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                title   mag\n",
       "10                     M 0.5 - 10km NE of Aguanga, CA  0.50\n",
       "11  M 2.8 - 53km SE of Punta Cana, Dominican Republic  2.77\n",
       "12                      M 0.5 - 9km NE of Aguanga, CA  0.50\n",
       "13         M 4.5 - 120km SSW of Banda Aceh, Indonesia  4.50\n",
       "14                   M 2.1 - 14km NW of Parkfield, CA  2.13"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[10:15, [19, 8]]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can use slicing syntax with `iloc` for both rows and columns:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>mag</th>\n",
       "      <th>magType</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>0.50</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2.77</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>0.50</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>4.50</td>\n",
       "      <td>mb</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>2.13</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     mag magType\n",
       "10  0.50      ml\n",
       "11  2.77      md\n",
       "12  0.50      ml\n",
       "13  4.50      mb\n",
       "14  2.13      md"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[10:15, 8:10]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "When using `loc`, we can slice on column names. This will be inclusive of the endpoint because you can't be expected to know what the next column name will be. As such, we have multiple ways to achieve the same end goal:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[10:15, 8:10].equals(\n",
    "    df.loc[10:14, 'mag':'magType']\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note there is also the `take()` method for There is also a `take()` method, which allows us to select specific row numbers (essentially `iloc` without having to specify the columns). For example, we can select the rows in positions 1 and 3:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>mag</th>\n",
       "      <th>magType</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2.77</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>4.50</td>\n",
       "      <td>mb</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     mag magType\n",
       "11  2.77      md\n",
       "13  4.50      mb"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[10:14, 'mag':'magType'].take([1, 3])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Looking up scalar values\n",
    "We used `loc` and `iloc` to grab subsets of the dataframe. However, if we are just interested in the specific value at a given [row, column], then we can use `iat` and `at`. \n",
    "\n",
    "We use `at` with labels:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.5"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.at[10, 'mag']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "...and `iat` with integer indices:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.5"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iat[10, 8]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Filtering\n",
    "We can filter our dataframes using a **Boolean mask**, which can be made as follows:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       False\n",
       "1       False\n",
       "2        True\n",
       "3       False\n",
       "4        True\n",
       "5        True\n",
       "6       False\n",
       "7       False\n",
       "8       False\n",
       "9        True\n",
       "10      False\n",
       "11       True\n",
       "12      False\n",
       "13       True\n",
       "14       True\n",
       "15      False\n",
       "16      False\n",
       "17      False\n",
       "18      False\n",
       "19      False\n",
       "20       True\n",
       "21      False\n",
       "22      False\n",
       "23      False\n",
       "24      False\n",
       "25       True\n",
       "26       True\n",
       "27      False\n",
       "28      False\n",
       "29      False\n",
       "        ...  \n",
       "9302    False\n",
       "9303    False\n",
       "9304     True\n",
       "9305    False\n",
       "9306     True\n",
       "9307     True\n",
       "9308     True\n",
       "9309     True\n",
       "9310    False\n",
       "9311     True\n",
       "9312     True\n",
       "9313    False\n",
       "9314    False\n",
       "9315     True\n",
       "9316     True\n",
       "9317     True\n",
       "9318    False\n",
       "9319     True\n",
       "9320     True\n",
       "9321     True\n",
       "9322    False\n",
       "9323    False\n",
       "9324    False\n",
       "9325    False\n",
       "9326    False\n",
       "9327    False\n",
       "9328    False\n",
       "9329     True\n",
       "9330    False\n",
       "9331    False\n",
       "Name: mag, Length: 9332, dtype: bool"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.mag > 2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To use a mask for selection, we simply place it inside the brackets:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>alert</th>\n",
       "      <th>cdi</th>\n",
       "      <th>code</th>\n",
       "      <th>detail</th>\n",
       "      <th>dmin</th>\n",
       "      <th>felt</th>\n",
       "      <th>gap</th>\n",
       "      <th>ids</th>\n",
       "      <th>mag</th>\n",
       "      <th>magType</th>\n",
       "      <th>...</th>\n",
       "      <th>sources</th>\n",
       "      <th>status</th>\n",
       "      <th>time</th>\n",
       "      <th>title</th>\n",
       "      <th>tsunami</th>\n",
       "      <th>type</th>\n",
       "      <th>types</th>\n",
       "      <th>tz</th>\n",
       "      <th>updated</th>\n",
       "      <th>url</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>837</th>\n",
       "      <td>green</td>\n",
       "      <td>4.1</td>\n",
       "      <td>1000haa3</td>\n",
       "      <td>https://earthquake.usgs.gov/fdsnws/event/1/que...</td>\n",
       "      <td>1.763</td>\n",
       "      <td>3.0</td>\n",
       "      <td>14.0</td>\n",
       "      <td>,us1000haa3,pt18283003,at00pgehsk,</td>\n",
       "      <td>7.0</td>\n",
       "      <td>mww</td>\n",
       "      <td>...</td>\n",
       "      <td>,us,pt,at,</td>\n",
       "      <td>reviewed</td>\n",
       "      <td>1539204500290</td>\n",
       "      <td>M 7.0 - 117km E of Kimbe, Papua New Guinea</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "      <td>,dyfi,finite-fault,general-text,geoserve,groun...</td>\n",
       "      <td>600.0</td>\n",
       "      <td>1539378744253</td>\n",
       "      <td>https://earthquake.usgs.gov/earthquakes/eventp...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5263</th>\n",
       "      <td>red</td>\n",
       "      <td>8.4</td>\n",
       "      <td>1000h3p4</td>\n",
       "      <td>https://earthquake.usgs.gov/fdsnws/event/1/que...</td>\n",
       "      <td>1.589</td>\n",
       "      <td>18.0</td>\n",
       "      <td>27.0</td>\n",
       "      <td>,us1000h3p4,us1000h4p4,</td>\n",
       "      <td>7.5</td>\n",
       "      <td>mww</td>\n",
       "      <td>...</td>\n",
       "      <td>,us,us,</td>\n",
       "      <td>reviewed</td>\n",
       "      <td>1538128963480</td>\n",
       "      <td>M 7.5 - 78km N of Palu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "      <td>,dyfi,finite-fault,general-text,geoserve,groun...</td>\n",
       "      <td>480.0</td>\n",
       "      <td>1539123134531</td>\n",
       "      <td>https://earthquake.usgs.gov/earthquakes/eventp...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      alert  cdi      code                                             detail  \\\n",
       "837   green  4.1  1000haa3  https://earthquake.usgs.gov/fdsnws/event/1/que...   \n",
       "5263    red  8.4  1000h3p4  https://earthquake.usgs.gov/fdsnws/event/1/que...   \n",
       "\n",
       "       dmin  felt   gap                                 ids  mag magType  \\\n",
       "837   1.763   3.0  14.0  ,us1000haa3,pt18283003,at00pgehsk,  7.0     mww   \n",
       "5263  1.589  18.0  27.0             ,us1000h3p4,us1000h4p4,  7.5     mww   \n",
       "\n",
       "                            ...                             sources    status  \\\n",
       "837                         ...                          ,us,pt,at,  reviewed   \n",
       "5263                        ...                             ,us,us,  reviewed   \n",
       "\n",
       "               time                                       title  tsunami  \\\n",
       "837   1539204500290  M 7.0 - 117km E of Kimbe, Papua New Guinea        1   \n",
       "5263  1538128963480           M 7.5 - 78km N of Palu, Indonesia        1   \n",
       "\n",
       "            type                                              types     tz  \\\n",
       "837   earthquake  ,dyfi,finite-fault,general-text,geoserve,groun...  600.0   \n",
       "5263  earthquake  ,dyfi,finite-fault,general-text,geoserve,groun...  480.0   \n",
       "\n",
       "            updated                                                url  \n",
       "837   1539378744253  https://earthquake.usgs.gov/earthquakes/eventp...  \n",
       "5263  1539123134531  https://earthquake.usgs.gov/earthquakes/eventp...  \n",
       "\n",
       "[2 rows x 26 columns]"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[df.mag >= 7.0]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can use masks with `loc`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>alert</th>\n",
       "      <th>mag</th>\n",
       "      <th>magType</th>\n",
       "      <th>title</th>\n",
       "      <th>tsunami</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>837</th>\n",
       "      <td>green</td>\n",
       "      <td>7.0</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 7.0 - 117km E of Kimbe, Papua New Guinea</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5263</th>\n",
       "      <td>red</td>\n",
       "      <td>7.5</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 7.5 - 78km N of Palu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      alert  mag magType                                       title  tsunami  \\\n",
       "837   green  7.0     mww  M 7.0 - 117km E of Kimbe, Papua New Guinea        1   \n",
       "5263    red  7.5     mww           M 7.5 - 78km N of Palu, Indonesia        1   \n",
       "\n",
       "            type  \n",
       "837   earthquake  \n",
       "5263  earthquake  "
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[\n",
    "    df.mag >= 7.0,\n",
    "    ['alert', 'mag', 'magType', 'title', 'tsunami', 'type']\n",
    "]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Masks can be created using multiple criteria when combined with bitwise operators `&` for AND and `|` for OR. We must also surround each criterion with parentheses. We can't use `and`/`or` here because we need to evaluate row by row:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>alert</th>\n",
       "      <th>mag</th>\n",
       "      <th>magType</th>\n",
       "      <th>title</th>\n",
       "      <th>tsunami</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>5263</th>\n",
       "      <td>red</td>\n",
       "      <td>7.5</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 7.5 - 78km N of Palu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     alert  mag magType                              title  tsunami  \\\n",
       "5263   red  7.5     mww  M 7.5 - 78km N of Palu, Indonesia        1   \n",
       "\n",
       "            type  \n",
       "5263  earthquake  "
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[\n",
    "    (df.tsunami == 1) & (df.alert == 'red'),\n",
    "    ['alert', 'mag', 'magType', 'title', 'tsunami', 'type']\n",
    "]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "An example with an OR condition, which is must less restrictive:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>alert</th>\n",
       "      <th>mag</th>\n",
       "      <th>magType</th>\n",
       "      <th>title</th>\n",
       "      <th>tsunami</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.00</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 5.0 - 165km NNW of Flying Fish Cove, Christm...</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>118</th>\n",
       "      <td>green</td>\n",
       "      <td>6.70</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 6.7 - 262km NW of Ozernovskiy, Russia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>501</th>\n",
       "      <td>green</td>\n",
       "      <td>5.60</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 5.6 - 128km SE of Kimbe, Papua New Guinea</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>799</th>\n",
       "      <td>green</td>\n",
       "      <td>6.50</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 6.5 - 148km S of Severo-Kuril'sk, Russia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>816</th>\n",
       "      <td>green</td>\n",
       "      <td>6.20</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 6.2 - 94km SW of Kokopo, Papua New Guinea</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>826</th>\n",
       "      <td>green</td>\n",
       "      <td>5.90</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 5.9 - 117km ESE of Kimbe, Papua New Guinea</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>829</th>\n",
       "      <td>green</td>\n",
       "      <td>5.90</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 5.9 - 113km ESE of Kimbe, Papua New Guinea</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>837</th>\n",
       "      <td>green</td>\n",
       "      <td>7.00</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 7.0 - 117km E of Kimbe, Papua New Guinea</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>838</th>\n",
       "      <td>green</td>\n",
       "      <td>6.10</td>\n",
       "      <td>mb</td>\n",
       "      <td>M 6.1 - 132km E of Kimbe, Papua New Guinea</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1015</th>\n",
       "      <td>green</td>\n",
       "      <td>5.00</td>\n",
       "      <td>ml</td>\n",
       "      <td>M 5.0 - 61km SSW of Chignik Lake, Alaska</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1018</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.30</td>\n",
       "      <td>mb</td>\n",
       "      <td>M 5.3 - 65km NNW of Lae, Papua New Guinea</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1056</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.40</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 5.4 - 62km NW of Finschhafen, Papua New Guinea</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1273</th>\n",
       "      <td>green</td>\n",
       "      <td>4.00</td>\n",
       "      <td>ml</td>\n",
       "      <td>M 4.0 - 71km SW of Kaktovik, Alaska</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1406</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.10</td>\n",
       "      <td>mb</td>\n",
       "      <td>M 5.1 - 13km E of Palu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1698</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.10</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 5.1 - 14km ENE of Sambelia, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1795</th>\n",
       "      <td>green</td>\n",
       "      <td>4.00</td>\n",
       "      <td>ml</td>\n",
       "      <td>M 4.0 - 60km WNW of Valdez, Alaska</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2034</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.00</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 5.0 - 11km ESE of Kimbe, Papua New Guinea</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2414</th>\n",
       "      <td>green</td>\n",
       "      <td>3.83</td>\n",
       "      <td>mw</td>\n",
       "      <td>M 3.8 - 5km SW of Tres Pinos, CA</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2752</th>\n",
       "      <td>green</td>\n",
       "      <td>4.00</td>\n",
       "      <td>ml</td>\n",
       "      <td>M 4.0 - 67km SSW of Kaktovik, Alaska</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3112</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.30</td>\n",
       "      <td>mb</td>\n",
       "      <td>M 5.3 - 29km SSW of Nggongi, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3150</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.00</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 5.0 - 38km S of Nggongi Satu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3605</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.00</td>\n",
       "      <td>mb</td>\n",
       "      <td>M 5.0 - 50km WSW of Kasiguncu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3609</th>\n",
       "      <td>green</td>\n",
       "      <td>5.60</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 5.6 - 33km SSW of Nggongi Satu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3692</th>\n",
       "      <td>green</td>\n",
       "      <td>5.90</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 5.9 - 30km SSW of Nggongi, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3699</th>\n",
       "      <td>green</td>\n",
       "      <td>6.00</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 6.0 - 33km S of Nggongi Satu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3707</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.20</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 5.2 - 25km N of Palu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3709</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.40</td>\n",
       "      <td>mb</td>\n",
       "      <td>M 5.4 - 31km S of Nggongi Satu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3714</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.00</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 5.0 - 33km SSW of Nggongi Satu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4027</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.10</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 5.1 - 101km NNW of Palu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4154</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.00</td>\n",
       "      <td>mb</td>\n",
       "      <td>M 5.0 - 106km NNW of Lae, Papua New Guinea</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4827</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.10</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 5.1 - 49km W of Kasiguncu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4888</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.10</td>\n",
       "      <td>mb</td>\n",
       "      <td>M 5.1 - 53km W of Kasiguncu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4988</th>\n",
       "      <td>green</td>\n",
       "      <td>4.41</td>\n",
       "      <td>mw</td>\n",
       "      <td>M 4.4 - 1km SE of Delta, B.C., MX</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5054</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.00</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 5.0 - 55km WSW of Kasiguncu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5146</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.00</td>\n",
       "      <td>mb</td>\n",
       "      <td>M 5.0 - 45km SSW of Palu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5179</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.40</td>\n",
       "      <td>mb</td>\n",
       "      <td>M 5.4 - 113km NNW of Palu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5195</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.20</td>\n",
       "      <td>mb</td>\n",
       "      <td>M 5.2 - 58km S of Palu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5196</th>\n",
       "      <td>green</td>\n",
       "      <td>5.70</td>\n",
       "      <td>ms_20</td>\n",
       "      <td>M 5.7 - 107km N of Palu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5214</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.10</td>\n",
       "      <td>mb</td>\n",
       "      <td>M 5.1 - 47km N of Palu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5240</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.20</td>\n",
       "      <td>mb</td>\n",
       "      <td>M 5.2 - 68km SSE of Palu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5244</th>\n",
       "      <td>green</td>\n",
       "      <td>5.70</td>\n",
       "      <td>mb</td>\n",
       "      <td>M 5.7 - 17km NNE of Palu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5245</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.10</td>\n",
       "      <td>mb</td>\n",
       "      <td>M 5.1 - 42km N of Palu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5250</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.40</td>\n",
       "      <td>mb</td>\n",
       "      <td>M 5.4 - 24km N of Palu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5256</th>\n",
       "      <td>green</td>\n",
       "      <td>5.80</td>\n",
       "      <td>mb</td>\n",
       "      <td>M 5.8 - 21km SSE of Palu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5258</th>\n",
       "      <td>green</td>\n",
       "      <td>5.70</td>\n",
       "      <td>mb</td>\n",
       "      <td>M 5.7 - 17km E of Palu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5259</th>\n",
       "      <td>green</td>\n",
       "      <td>5.80</td>\n",
       "      <td>mb</td>\n",
       "      <td>M 5.8 - 99km N of Palu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5263</th>\n",
       "      <td>red</td>\n",
       "      <td>7.50</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 7.5 - 78km N of Palu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5289</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.00</td>\n",
       "      <td>mb</td>\n",
       "      <td>M 5.0 - 60km N of Palu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5321</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.40</td>\n",
       "      <td>mb</td>\n",
       "      <td>M 5.4 - 77km NNE of Palu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5323</th>\n",
       "      <td>green</td>\n",
       "      <td>6.10</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 6.1 - 55km NNW of Palu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5574</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.20</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 5.2 - 91km WNW of Panguna, Papua New Guinea</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5790</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.10</td>\n",
       "      <td>mb</td>\n",
       "      <td>M 5.1 - 117km N of Saumlaki, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6004</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.10</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 5.1 - 19km WNW of Langsa, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6134</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.00</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 5.0 - 85km W of Manokwari, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7160</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.00</td>\n",
       "      <td>mb</td>\n",
       "      <td>M 5.0 - 10km WSW of Kainantu, Papua New Guinea</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8561</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.40</td>\n",
       "      <td>mb</td>\n",
       "      <td>M 5.4 - 228km S of Taron, Papua New Guinea</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8624</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.10</td>\n",
       "      <td>mb</td>\n",
       "      <td>M 5.1 - 278km SE of Pondaguitan, Philippines</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9133</th>\n",
       "      <td>green</td>\n",
       "      <td>5.10</td>\n",
       "      <td>ml</td>\n",
       "      <td>M 5.1 - 64km SSW of Kaktovik, Alaska</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9175</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.20</td>\n",
       "      <td>mb</td>\n",
       "      <td>M 5.2 - 126km N of Dili, East Timor</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9304</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.10</td>\n",
       "      <td>mb</td>\n",
       "      <td>M 5.1 - 34km NW of Finschhafen, Papua New Guinea</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>61 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      alert   mag magType                                              title  \\\n",
       "36      NaN  5.00     mww  M 5.0 - 165km NNW of Flying Fish Cove, Christm...   \n",
       "118   green  6.70     mww            M 6.7 - 262km NW of Ozernovskiy, Russia   \n",
       "501   green  5.60     mww        M 5.6 - 128km SE of Kimbe, Papua New Guinea   \n",
       "799   green  6.50     mww         M 6.5 - 148km S of Severo-Kuril'sk, Russia   \n",
       "816   green  6.20     mww        M 6.2 - 94km SW of Kokopo, Papua New Guinea   \n",
       "826   green  5.90     mww       M 5.9 - 117km ESE of Kimbe, Papua New Guinea   \n",
       "829   green  5.90     mww       M 5.9 - 113km ESE of Kimbe, Papua New Guinea   \n",
       "837   green  7.00     mww         M 7.0 - 117km E of Kimbe, Papua New Guinea   \n",
       "838   green  6.10      mb         M 6.1 - 132km E of Kimbe, Papua New Guinea   \n",
       "1015  green  5.00      ml           M 5.0 - 61km SSW of Chignik Lake, Alaska   \n",
       "1018    NaN  5.30      mb          M 5.3 - 65km NNW of Lae, Papua New Guinea   \n",
       "1056    NaN  5.40     mww   M 5.4 - 62km NW of Finschhafen, Papua New Guinea   \n",
       "1273  green  4.00      ml                M 4.0 - 71km SW of Kaktovik, Alaska   \n",
       "1406    NaN  5.10      mb                  M 5.1 - 13km E of Palu, Indonesia   \n",
       "1698    NaN  5.10     mww            M 5.1 - 14km ENE of Sambelia, Indonesia   \n",
       "1795  green  4.00      ml                 M 4.0 - 60km WNW of Valdez, Alaska   \n",
       "2034    NaN  5.00     mww        M 5.0 - 11km ESE of Kimbe, Papua New Guinea   \n",
       "2414  green  3.83      mw                   M 3.8 - 5km SW of Tres Pinos, CA   \n",
       "2752  green  4.00      ml               M 4.0 - 67km SSW of Kaktovik, Alaska   \n",
       "3112    NaN  5.30      mb             M 5.3 - 29km SSW of Nggongi, Indonesia   \n",
       "3150    NaN  5.00     mww          M 5.0 - 38km S of Nggongi Satu, Indonesia   \n",
       "3605    NaN  5.00      mb           M 5.0 - 50km WSW of Kasiguncu, Indonesia   \n",
       "3609  green  5.60     mww        M 5.6 - 33km SSW of Nggongi Satu, Indonesia   \n",
       "3692  green  5.90     mww             M 5.9 - 30km SSW of Nggongi, Indonesia   \n",
       "3699  green  6.00     mww          M 6.0 - 33km S of Nggongi Satu, Indonesia   \n",
       "3707    NaN  5.20     mww                  M 5.2 - 25km N of Palu, Indonesia   \n",
       "3709    NaN  5.40      mb          M 5.4 - 31km S of Nggongi Satu, Indonesia   \n",
       "3714    NaN  5.00     mww        M 5.0 - 33km SSW of Nggongi Satu, Indonesia   \n",
       "4027    NaN  5.10     mww               M 5.1 - 101km NNW of Palu, Indonesia   \n",
       "4154    NaN  5.00      mb         M 5.0 - 106km NNW of Lae, Papua New Guinea   \n",
       "...     ...   ...     ...                                                ...   \n",
       "4827    NaN  5.10     mww             M 5.1 - 49km W of Kasiguncu, Indonesia   \n",
       "4888    NaN  5.10      mb             M 5.1 - 53km W of Kasiguncu, Indonesia   \n",
       "4988  green  4.41      mw                  M 4.4 - 1km SE of Delta, B.C., MX   \n",
       "5054    NaN  5.00     mww           M 5.0 - 55km WSW of Kasiguncu, Indonesia   \n",
       "5146    NaN  5.00      mb                M 5.0 - 45km SSW of Palu, Indonesia   \n",
       "5179    NaN  5.40      mb               M 5.4 - 113km NNW of Palu, Indonesia   \n",
       "5195    NaN  5.20      mb                  M 5.2 - 58km S of Palu, Indonesia   \n",
       "5196  green  5.70   ms_20                 M 5.7 - 107km N of Palu, Indonesia   \n",
       "5214    NaN  5.10      mb                  M 5.1 - 47km N of Palu, Indonesia   \n",
       "5240    NaN  5.20      mb                M 5.2 - 68km SSE of Palu, Indonesia   \n",
       "5244  green  5.70      mb                M 5.7 - 17km NNE of Palu, Indonesia   \n",
       "5245    NaN  5.10      mb                  M 5.1 - 42km N of Palu, Indonesia   \n",
       "5250    NaN  5.40      mb                  M 5.4 - 24km N of Palu, Indonesia   \n",
       "5256  green  5.80      mb                M 5.8 - 21km SSE of Palu, Indonesia   \n",
       "5258  green  5.70      mb                  M 5.7 - 17km E of Palu, Indonesia   \n",
       "5259  green  5.80      mb                  M 5.8 - 99km N of Palu, Indonesia   \n",
       "5263    red  7.50     mww                  M 7.5 - 78km N of Palu, Indonesia   \n",
       "5289    NaN  5.00      mb                  M 5.0 - 60km N of Palu, Indonesia   \n",
       "5321    NaN  5.40      mb                M 5.4 - 77km NNE of Palu, Indonesia   \n",
       "5323  green  6.10     mww                M 6.1 - 55km NNW of Palu, Indonesia   \n",
       "5574    NaN  5.20     mww      M 5.2 - 91km WNW of Panguna, Papua New Guinea   \n",
       "5790    NaN  5.10      mb             M 5.1 - 117km N of Saumlaki, Indonesia   \n",
       "6004    NaN  5.10     mww              M 5.1 - 19km WNW of Langsa, Indonesia   \n",
       "6134    NaN  5.00     mww             M 5.0 - 85km W of Manokwari, Indonesia   \n",
       "7160    NaN  5.00      mb     M 5.0 - 10km WSW of Kainantu, Papua New Guinea   \n",
       "8561    NaN  5.40      mb         M 5.4 - 228km S of Taron, Papua New Guinea   \n",
       "8624    NaN  5.10      mb       M 5.1 - 278km SE of Pondaguitan, Philippines   \n",
       "9133  green  5.10      ml               M 5.1 - 64km SSW of Kaktovik, Alaska   \n",
       "9175    NaN  5.20      mb                M 5.2 - 126km N of Dili, East Timor   \n",
       "9304    NaN  5.10      mb   M 5.1 - 34km NW of Finschhafen, Papua New Guinea   \n",
       "\n",
       "      tsunami        type  \n",
       "36          1  earthquake  \n",
       "118         1  earthquake  \n",
       "501         1  earthquake  \n",
       "799         1  earthquake  \n",
       "816         1  earthquake  \n",
       "826         1  earthquake  \n",
       "829         1  earthquake  \n",
       "837         1  earthquake  \n",
       "838         1  earthquake  \n",
       "1015        1  earthquake  \n",
       "1018        1  earthquake  \n",
       "1056        1  earthquake  \n",
       "1273        1  earthquake  \n",
       "1406        1  earthquake  \n",
       "1698        1  earthquake  \n",
       "1795        1  earthquake  \n",
       "2034        1  earthquake  \n",
       "2414        1  earthquake  \n",
       "2752        1  earthquake  \n",
       "3112        1  earthquake  \n",
       "3150        1  earthquake  \n",
       "3605        1  earthquake  \n",
       "3609        1  earthquake  \n",
       "3692        1  earthquake  \n",
       "3699        1  earthquake  \n",
       "3707        1  earthquake  \n",
       "3709        1  earthquake  \n",
       "3714        1  earthquake  \n",
       "4027        1  earthquake  \n",
       "4154        1  earthquake  \n",
       "...       ...         ...  \n",
       "4827        1  earthquake  \n",
       "4888        1  earthquake  \n",
       "4988        1  earthquake  \n",
       "5054        1  earthquake  \n",
       "5146        1  earthquake  \n",
       "5179        1  earthquake  \n",
       "5195        1  earthquake  \n",
       "5196        1  earthquake  \n",
       "5214        1  earthquake  \n",
       "5240        1  earthquake  \n",
       "5244        1  earthquake  \n",
       "5245        1  earthquake  \n",
       "5250        1  earthquake  \n",
       "5256        1  earthquake  \n",
       "5258        1  earthquake  \n",
       "5259        1  earthquake  \n",
       "5263        1  earthquake  \n",
       "5289        1  earthquake  \n",
       "5321        1  earthquake  \n",
       "5323        1  earthquake  \n",
       "5574        1  earthquake  \n",
       "5790        1  earthquake  \n",
       "6004        1  earthquake  \n",
       "6134        1  earthquake  \n",
       "7160        1  earthquake  \n",
       "8561        1  earthquake  \n",
       "8624        1  earthquake  \n",
       "9133        1  earthquake  \n",
       "9175        1  earthquake  \n",
       "9304        1  earthquake  \n",
       "\n",
       "[61 rows x 6 columns]"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[\n",
    "    (df.tsunami == 1) | (df.alert == 'red'),\n",
    "    ['alert', 'mag', 'magType', 'title', 'tsunami', 'type']\n",
    "]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Masks can be any criteria that results in a Boolean. For example, we can select all earthquakes with the string `Alaska` in the `place` column with a non-null value for the `alert` column. To get non-nulls, we can use the `isnull()` method with the pandas negation operator (`~`) or the `notnull()` method:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>alert</th>\n",
       "      <th>mag</th>\n",
       "      <th>magType</th>\n",
       "      <th>title</th>\n",
       "      <th>tsunami</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1015</th>\n",
       "      <td>green</td>\n",
       "      <td>5.0</td>\n",
       "      <td>ml</td>\n",
       "      <td>M 5.0 - 61km SSW of Chignik Lake, Alaska</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1273</th>\n",
       "      <td>green</td>\n",
       "      <td>4.0</td>\n",
       "      <td>ml</td>\n",
       "      <td>M 4.0 - 71km SW of Kaktovik, Alaska</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1795</th>\n",
       "      <td>green</td>\n",
       "      <td>4.0</td>\n",
       "      <td>ml</td>\n",
       "      <td>M 4.0 - 60km WNW of Valdez, Alaska</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2752</th>\n",
       "      <td>green</td>\n",
       "      <td>4.0</td>\n",
       "      <td>ml</td>\n",
       "      <td>M 4.0 - 67km SSW of Kaktovik, Alaska</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3260</th>\n",
       "      <td>green</td>\n",
       "      <td>3.9</td>\n",
       "      <td>ml</td>\n",
       "      <td>M 3.9 - 44km N of North Nenana, Alaska</td>\n",
       "      <td>0</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4101</th>\n",
       "      <td>green</td>\n",
       "      <td>4.2</td>\n",
       "      <td>ml</td>\n",
       "      <td>M 4.2 - 131km NNW of Arctic Village, Alaska</td>\n",
       "      <td>0</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6897</th>\n",
       "      <td>green</td>\n",
       "      <td>3.8</td>\n",
       "      <td>ml</td>\n",
       "      <td>M 3.8 - 80km SSW of Kaktovik, Alaska</td>\n",
       "      <td>0</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8524</th>\n",
       "      <td>green</td>\n",
       "      <td>3.8</td>\n",
       "      <td>ml</td>\n",
       "      <td>M 3.8 - 69km SSW of Kaktovik, Alaska</td>\n",
       "      <td>0</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9133</th>\n",
       "      <td>green</td>\n",
       "      <td>5.1</td>\n",
       "      <td>ml</td>\n",
       "      <td>M 5.1 - 64km SSW of Kaktovik, Alaska</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      alert  mag magType                                        title  \\\n",
       "1015  green  5.0      ml     M 5.0 - 61km SSW of Chignik Lake, Alaska   \n",
       "1273  green  4.0      ml          M 4.0 - 71km SW of Kaktovik, Alaska   \n",
       "1795  green  4.0      ml           M 4.0 - 60km WNW of Valdez, Alaska   \n",
       "2752  green  4.0      ml         M 4.0 - 67km SSW of Kaktovik, Alaska   \n",
       "3260  green  3.9      ml       M 3.9 - 44km N of North Nenana, Alaska   \n",
       "4101  green  4.2      ml  M 4.2 - 131km NNW of Arctic Village, Alaska   \n",
       "6897  green  3.8      ml         M 3.8 - 80km SSW of Kaktovik, Alaska   \n",
       "8524  green  3.8      ml         M 3.8 - 69km SSW of Kaktovik, Alaska   \n",
       "9133  green  5.1      ml         M 5.1 - 64km SSW of Kaktovik, Alaska   \n",
       "\n",
       "      tsunami        type  \n",
       "1015        1  earthquake  \n",
       "1273        1  earthquake  \n",
       "1795        1  earthquake  \n",
       "2752        1  earthquake  \n",
       "3260        0  earthquake  \n",
       "4101        0  earthquake  \n",
       "6897        0  earthquake  \n",
       "8524        0  earthquake  \n",
       "9133        1  earthquake  "
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[\n",
    "    (df.place.str.contains('Alaska')) & (df.alert.notnull()),\n",
    "    ['alert', 'mag', 'magType', 'title', 'tsunami', 'type']\n",
    "]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can even use regular expressions here:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>alert</th>\n",
       "      <th>mag</th>\n",
       "      <th>magType</th>\n",
       "      <th>title</th>\n",
       "      <th>tsunami</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1465</th>\n",
       "      <td>green</td>\n",
       "      <td>3.83</td>\n",
       "      <td>mw</td>\n",
       "      <td>M 3.8 - 109km WNW of Trinidad, CA</td>\n",
       "      <td>0</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2414</th>\n",
       "      <td>green</td>\n",
       "      <td>3.83</td>\n",
       "      <td>mw</td>\n",
       "      <td>M 3.8 - 5km SW of Tres Pinos, CA</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      alert   mag magType                              title  tsunami  \\\n",
       "1465  green  3.83      mw  M 3.8 - 109km WNW of Trinidad, CA        0   \n",
       "2414  green  3.83      mw   M 3.8 - 5km SW of Tres Pinos, CA        1   \n",
       "\n",
       "            type  \n",
       "1465  earthquake  \n",
       "2414  earthquake  "
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[\n",
    "    (df.place.str.contains(r'CA|California$')) & (df.mag > 3.8),\n",
    "    ['alert', 'mag', 'magType', 'title', 'tsunami', 'type']\n",
    "]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can use the `between()` method to turn 2 individual checks (is less than or equal some maximum value and is greater than or equal to some minimum value) into a single one. Note this is inclusive of the endpoint by default:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>alert</th>\n",
       "      <th>mag</th>\n",
       "      <th>magType</th>\n",
       "      <th>title</th>\n",
       "      <th>tsunami</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>118</th>\n",
       "      <td>green</td>\n",
       "      <td>6.7</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 6.7 - 262km NW of Ozernovskiy, Russia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>799</th>\n",
       "      <td>green</td>\n",
       "      <td>6.5</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 6.5 - 148km S of Severo-Kuril'sk, Russia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>837</th>\n",
       "      <td>green</td>\n",
       "      <td>7.0</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 7.0 - 117km E of Kimbe, Papua New Guinea</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4363</th>\n",
       "      <td>green</td>\n",
       "      <td>6.7</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 6.7 - 263km NNE of Ndoi Island, Fiji</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5263</th>\n",
       "      <td>red</td>\n",
       "      <td>7.5</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 7.5 - 78km N of Palu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      alert  mag magType                                       title  tsunami  \\\n",
       "118   green  6.7     mww     M 6.7 - 262km NW of Ozernovskiy, Russia        1   \n",
       "799   green  6.5     mww  M 6.5 - 148km S of Severo-Kuril'sk, Russia        1   \n",
       "837   green  7.0     mww  M 7.0 - 117km E of Kimbe, Papua New Guinea        1   \n",
       "4363  green  6.7     mww      M 6.7 - 263km NNE of Ndoi Island, Fiji        1   \n",
       "5263    red  7.5     mww           M 7.5 - 78km N of Palu, Indonesia        1   \n",
       "\n",
       "            type  \n",
       "118   earthquake  \n",
       "799   earthquake  \n",
       "837   earthquake  \n",
       "4363  earthquake  \n",
       "5263  earthquake  "
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[\n",
    "    df.mag.between(6.5, 7.5),\n",
    "    ['alert', 'mag', 'magType', 'title', 'tsunami', 'type']\n",
    "]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can use the `isin()` method to check for membership in a list of values:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>alert</th>\n",
       "      <th>mag</th>\n",
       "      <th>magType</th>\n",
       "      <th>title</th>\n",
       "      <th>tsunami</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>5263</th>\n",
       "      <td>red</td>\n",
       "      <td>7.5</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 7.5 - 78km N of Palu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     alert  mag magType                              title  tsunami  \\\n",
       "5263   red  7.5     mww  M 7.5 - 78km N of Palu, Indonesia        1   \n",
       "\n",
       "            type  \n",
       "5263  earthquake  "
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[\n",
    "    df.alert.isin(['orange', 'red']),\n",
    "    ['alert', 'mag', 'magType', 'title', 'tsunami', 'type']\n",
    "]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can grab the index of the minimum and maximum values of a given column and use those to select the entire row where they occur:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2409, 5263]"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[df.mag.idxmin(), df.mag.idxmax()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>alert</th>\n",
       "      <th>mag</th>\n",
       "      <th>magType</th>\n",
       "      <th>title</th>\n",
       "      <th>tsunami</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2409</th>\n",
       "      <td>NaN</td>\n",
       "      <td>-1.26</td>\n",
       "      <td>ml</td>\n",
       "      <td>M -1.3 - 41km ENE of Adak, Alaska</td>\n",
       "      <td>0</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5263</th>\n",
       "      <td>red</td>\n",
       "      <td>7.50</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 7.5 - 78km N of Palu, Indonesia</td>\n",
       "      <td>1</td>\n",
       "      <td>earthquake</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     alert   mag magType                              title  tsunami  \\\n",
       "2409   NaN -1.26      ml  M -1.3 - 41km ENE of Adak, Alaska        0   \n",
       "5263   red  7.50     mww  M 7.5 - 78km N of Palu, Indonesia        1   \n",
       "\n",
       "            type  \n",
       "2409  earthquake  \n",
       "5263  earthquake  "
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[\n",
    "    [df.mag.idxmin(), df.mag.idxmax()],\n",
    "    ['alert', 'mag', 'magType', 'title', 'tsunami', 'type']\n",
    "]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Using the `filter()` method, we can grab columns of a dataframe by passing a list to `items`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>mag</th>\n",
       "      <th>magType</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.35</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.29</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3.42</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.44</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2.16</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    mag magType\n",
       "0  1.35      ml\n",
       "1  1.29      ml\n",
       "2  3.42      ml\n",
       "3  0.44      ml\n",
       "4  2.16      md"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.filter(items=['mag', 'magType']).head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can also grab all the columns that contain a string with the `like` parameter:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>mag</th>\n",
       "      <th>magType</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.35</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.29</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3.42</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.44</td>\n",
       "      <td>ml</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2.16</td>\n",
       "      <td>md</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    mag magType\n",
       "0  1.35      ml\n",
       "1  1.29      ml\n",
       "2  3.42      ml\n",
       "3  0.44      ml\n",
       "4  2.16      md"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.filter(like='mag').head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can even use regular expressions; here, we select any columns that start with `t`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>time</th>\n",
       "      <th>title</th>\n",
       "      <th>tsunami</th>\n",
       "      <th>type</th>\n",
       "      <th>types</th>\n",
       "      <th>tz</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1539475168010</td>\n",
       "      <td>M 1.4 - 9km NE of Aguanga, CA</td>\n",
       "      <td>0</td>\n",
       "      <td>earthquake</td>\n",
       "      <td>,geoserve,nearby-cities,origin,phase-data,</td>\n",
       "      <td>-480.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1539475129610</td>\n",
       "      <td>M 1.3 - 9km NE of Aguanga, CA</td>\n",
       "      <td>0</td>\n",
       "      <td>earthquake</td>\n",
       "      <td>,geoserve,nearby-cities,origin,phase-data,</td>\n",
       "      <td>-480.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1539475062610</td>\n",
       "      <td>M 3.4 - 8km NE of Aguanga, CA</td>\n",
       "      <td>0</td>\n",
       "      <td>earthquake</td>\n",
       "      <td>,dyfi,focal-mechanism,geoserve,nearby-cities,o...</td>\n",
       "      <td>-480.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1539474978070</td>\n",
       "      <td>M 0.4 - 9km NE of Aguanga, CA</td>\n",
       "      <td>0</td>\n",
       "      <td>earthquake</td>\n",
       "      <td>,geoserve,nearby-cities,origin,phase-data,</td>\n",
       "      <td>-480.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1539474716050</td>\n",
       "      <td>M 2.2 - 10km NW of Avenal, CA</td>\n",
       "      <td>0</td>\n",
       "      <td>earthquake</td>\n",
       "      <td>,geoserve,nearby-cities,origin,phase-data,scit...</td>\n",
       "      <td>-480.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            time                          title  tsunami        type  \\\n",
       "0  1539475168010  M 1.4 - 9km NE of Aguanga, CA        0  earthquake   \n",
       "1  1539475129610  M 1.3 - 9km NE of Aguanga, CA        0  earthquake   \n",
       "2  1539475062610  M 3.4 - 8km NE of Aguanga, CA        0  earthquake   \n",
       "3  1539474978070  M 0.4 - 9km NE of Aguanga, CA        0  earthquake   \n",
       "4  1539474716050  M 2.2 - 10km NW of Avenal, CA        0  earthquake   \n",
       "\n",
       "                                               types     tz  \n",
       "0         ,geoserve,nearby-cities,origin,phase-data, -480.0  \n",
       "1         ,geoserve,nearby-cities,origin,phase-data, -480.0  \n",
       "2  ,dyfi,focal-mechanism,geoserve,nearby-cities,o... -480.0  \n",
       "3         ,geoserve,nearby-cities,origin,phase-data, -480.0  \n",
       "4  ,geoserve,nearby-cities,origin,phase-data,scit... -480.0  "
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.filter(regex=r'^t').head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can also use `filter()` along the rows, by passing in `axis=0`. Here we will use the `place` column as the index (we will cover `set_index()` in [chapter 3](https://github.com/stefmolin/Hands-On-Data-Analysis-with-Pandas/tree/master/ch_03)):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>mag</th>\n",
       "      <th>magType</th>\n",
       "      <th>title</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>place</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>160km NNW of Nago, Japan</th>\n",
       "      <td>4.6</td>\n",
       "      <td>mb</td>\n",
       "      <td>M 4.6 - 160km NNW of Nago, Japan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7km ESE of Asahi, Japan</th>\n",
       "      <td>5.2</td>\n",
       "      <td>mww</td>\n",
       "      <td>M 5.2 - 7km ESE of Asahi, Japan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14km E of Tomakomai, Japan</th>\n",
       "      <td>4.5</td>\n",
       "      <td>mwr</td>\n",
       "      <td>M 4.5 - 14km E of Tomakomai, Japan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>139km WSW of Naze, Japan</th>\n",
       "      <td>4.7</td>\n",
       "      <td>mb</td>\n",
       "      <td>M 4.7 - 139km WSW of Naze, Japan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>53km ESE of Kamaishi, Japan</th>\n",
       "      <td>4.6</td>\n",
       "      <td>mb</td>\n",
       "      <td>M 4.6 - 53km ESE of Kamaishi, Japan</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                             mag magType                                title\n",
       "place                                                                        \n",
       "160km NNW of Nago, Japan     4.6      mb     M 4.6 - 160km NNW of Nago, Japan\n",
       "7km ESE of Asahi, Japan      5.2     mww      M 5.2 - 7km ESE of Asahi, Japan\n",
       "14km E of Tomakomai, Japan   4.5     mwr   M 4.5 - 14km E of Tomakomai, Japan\n",
       "139km WSW of Naze, Japan     4.7      mb     M 4.7 - 139km WSW of Naze, Japan\n",
       "53km ESE of Kamaishi, Japan  4.6      mb  M 4.6 - 53km ESE of Kamaishi, Japan"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.set_index('place').filter(like='Japan', axis=0).filter(items=['mag', 'magType', 'title']).head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This also works on `Series` objects and will run on the index:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "place\n",
       "160km NNW of Nago, Japan          M 4.6 - 160km NNW of Nago, Japan\n",
       "7km ESE of Asahi, Japan            M 5.2 - 7km ESE of Asahi, Japan\n",
       "14km E of Tomakomai, Japan      M 4.5 - 14km E of Tomakomai, Japan\n",
       "139km WSW of Naze, Japan          M 4.7 - 139km WSW of Naze, Japan\n",
       "53km ESE of Kamaishi, Japan    M 4.6 - 53km ESE of Kamaishi, Japan\n",
       "Name: title, dtype: object"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.set_index('place').title.filter(like='Japan').head()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
